Skip to content

Commit 3c6b533

Browse files
committed
int (also literals as it seems) are signed by default
These patches eliminate an error found by cppcheck: src/hal/drivers/opto_ac5.c:432:13: error: Signed integer overflow for expression '1<<(31-i)'. [integerOverflow] mask=1<<(31-i);
1 parent c3e3e8b commit 3c6b533

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

src/hal/drivers/hal_gm.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,18 +1126,17 @@ read(void *arg, long period)
11261126
{
11271127
gm_device_t *device = (gm_device_t *)arg;
11281128
card *pCard = device->pCard;
1129-
int i;
11301129
hal_u32_t temp;
11311130

11321131
//basic card functionality: watchdog, switches, estop
11331132
card_mgr(arg, period);
11341133

11351134
//read parallel IOs
11361135
temp=pCard->gpio;
1137-
for(i = 0; i < 32; i++)
1136+
for(unsigned int i = 0; i < 32; i++)
11381137
{
1139-
*(device->gpio[i].in) = (hal_bit_t)((temp & (0x0001 << i)) == 0 ? 0 : 1);
1140-
*(device->gpio[i].inNot) = (hal_bit_t)((temp & (0x0001 << i)) == 0 ? 1 : 0);
1138+
*(device->gpio[i].in) = (hal_bit_t)((temp & ((unsigned int) 1 << i)) == 0 ? 0 : 1);
1139+
*(device->gpio[i].inNot) = (hal_bit_t)((temp & ((unsigned int) 1 << i)) == 0 ? 1 : 0);
11411140
}
11421141

11431142
//Read Encoders

src/hal/drivers/opto_ac5.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ Device_DigitalOutWrite(void *arg, long period)
401401
{
402402
board_data_t *pboard = (board_data_t *)arg;
403403
DigitalPinsParams *pDigital;
404-
int i, j, portnum=0;
404+
int portnum=0;
405405
unsigned long pins, offset=DATA_WRITE_OFFSET_0,mask;
406406

407407
// For each port.
@@ -412,7 +412,7 @@ Device_DigitalOutWrite(void *arg, long period)
412412
pins=0;
413413

414414
// For each pin.
415-
for(j = 0; j < 24; j++, pDigital++)
415+
for(unsigned int j = 0; j < 24; j++, pDigital++)
416416
{
417417
if ((pboard->port[portnum].mask & mask) !=0) //is it an output?
418418
{
@@ -427,16 +427,16 @@ Device_DigitalOutWrite(void *arg, long period)
427427

428428
// CHECK LED PINS
429429
pDigital = &pboard->port[portnum].io[23];//one before what we want to check
430-
for (i = 0;i < 2;i++)
430+
for (unsigned int i = 0; i < 2; i++)
431431
{
432-
mask=1<<(31-i);
432+
mask = (unsigned int) 1 << (31-i);
433433
pDigital++;
434434

435-
if ( *(pDigital->pValue) ==0 ) { pins |= mask; }
435+
if ( *(pDigital->pValue) == 0 ) { pins |= mask; }
436436
}
437437
// Write digital I/O register.
438438
writel(pins,pboard->base + (offset));
439-
portnum ++;
439+
portnum++;
440440
offset=DATA_WRITE_OFFSET_1; // set to port1 offset
441441
}
442442
}

0 commit comments

Comments
 (0)