Skip to content

Commit bc37cbe

Browse files
author
Hinnerk van Bruinehsen
committed
Merge pull request #1820 from N8Fear/cppcheck-cleanup
lint: take care of various warnings/errors issued by cppcheck
2 parents 9ba48e4 + 72115d6 commit bc37cbe

File tree

37 files changed

+143
-87
lines changed

37 files changed

+143
-87
lines changed

boards/avsextrem/drivers/avsextrem-smb380.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,15 +794,13 @@ int16_t SMB380_getBandWidthAbs(void)
794794

795795
void SMB380_softReset(void)
796796
{
797-
unsigned char ur;
798797
unsigned long cpsr = disableIRQ();
799798
SMB380_Prepare();
800799
SMB380_ssp_write(SMB380_CONTROL1, SMB380_CONTROL1_SOFT_RESET_MASK,
801800
SMB380_WRITE_REGISTER);
802-
ur = ((unsigned char)SMB380_ssp_read()) & SMB380_CONTROL1_SOFT_RESET_MASK;
801+
SMB380_ssp_read();
803802
SMB380_Unprepare();
804803
restoreIRQ(cpsr);
805-
ur = ur >> 1;
806804
}
807805

808806
void SMB380_setCustomerReg(unsigned char data)

boards/redbee-econotag/tools/ftditools/bbmc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,8 @@ int print_and_prompt(struct ftdi_device_list *devlist)
473473
size_t last = strlen(input) - 1;
474474

475475
if (input[last] == '\n') {
476+
/* cppcheck: input is accessed later via *s */
477+
/* cppcheck-suppress unreadVariable */
476478
input[last] = '\0';
477479
}
478480

@@ -534,7 +536,6 @@ void erase(struct ftdi_context *ftdic, const struct layout *l)
534536
int bb_mpsee(struct ftdi_context *ftdic, uint16_t dir, uint16_t val)
535537
{
536538
uint8_t buf[3];
537-
int ret;
538539

539540
/* command "set data bits low byte" */
540541
buf[0] = 0x80;
@@ -559,7 +560,7 @@ int bb_mpsee(struct ftdi_context *ftdic, uint16_t dir, uint16_t val)
559560
fprintf(stderr, "write %x %x %x\n", buf[0], buf[1], buf[2]);
560561
#endif
561562

562-
if ((ret = (ftdi_write_data(ftdic, buf, 3))) < 0) {
563+
if ((ftdi_write_data(ftdic, buf, 3)) < 0) {
563564
perror("ft2232_write error");
564565
fprintf(stderr, "ft2232_write command %x\n", buf[0]);
565566
return EXIT_FAILURE;

boards/redbee-econotag/tools/mc1322x-load.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ int main(int argc, char **argv)
203203

204204
while (1) {
205205
/* Wait for CONNECT */
206-
r = write(pfd, (const void *)"\0", 1);
206+
write(pfd, (const void *)"\0", 1);
207207
sleep(1);
208208
r = read(pfd, &buf[i], sizeof(buf) - 1 - i);
209209

@@ -249,7 +249,7 @@ int main(int argc, char **argv)
249249

250250
s = sbuf.st_size;
251251
printf("Sending %s (%i bytes)...\n", filename, s);
252-
r = write(pfd, (const void *)&s, 4);
252+
write(pfd, (const void *)&s, 4);
253253
i = 0;
254254
r = read(ffd, buf, 1);
255255

@@ -316,7 +316,7 @@ int main(int argc, char **argv)
316316

317317
s = sbuf.st_size;
318318
printf("Sending %s (%i bytes)...\n", second, s);
319-
r = write(pfd, (const void *)&s, 4);
319+
write(pfd, (const void *)&s, 4);
320320
i = 0;
321321
r = read(sfd, buf, 1);
322322

@@ -345,7 +345,7 @@ int main(int argc, char **argv)
345345
/* Send the remaining arguments */
346346
if (args) {
347347
printf("Sending %s\n", args);
348-
r = write(pfd, (const void *)args, strlen(args));
348+
write(pfd, (const void *)args, strlen(args));
349349
r = write(pfd, (const void *)",", 1);
350350
}
351351

cpu/arm_common/common.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ arm_irq_handler:
144144
MRS R1, CPSR
145145
MSR SPSR, R1
146146

147-
.if CPU != mc1322x
147+
.if (CPU != mc1322x)
148148
/* jump into vic interrupt */
149149
mov r0, #0xffffff00 /* lpc23xx */
150150
ldr r0, [r0]

cpu/arm_common/syscalls.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343
#define PRINTF(...)
4444
#endif
4545

46-
#ifdef MODULE_FAT
47-
#include "ff_ansi.h"
48-
#endif
49-
5046
/**
5147
* @name Heaps (defined in linker script)
5248
* @{
@@ -94,9 +90,6 @@ _off_t _lseek_r(struct _reent *r, int fd, _off_t pos, int whence)
9490
PRINTF("lseek [%i] pos %li whence %i\n", fd, pos, whence);
9591

9692
r->_errno = ENODEV;
97-
#ifdef MODULE_FAT
98-
result = ff_lseek_r(r, fd, pos, whence);
99-
#endif
10093

10194
PRINTF("lseek returned %li (0 is success)\n", result);
10295
return result;
@@ -111,9 +104,6 @@ int _open_r(struct _reent *r, const char *name, int mode)
111104
PRINTF("open '%s' mode %#x\n", name, mode);
112105

113106
r->_errno = ENODEV; // no such device
114-
#ifdef MODULE_FAT
115-
ret = ff_open_r(r, name, mode);
116-
#endif
117107

118108
PRINTF("open [%i] errno %i\n", ret, r->_errno);
119109
return ret;
@@ -127,9 +117,6 @@ int _stat_r(struct _reent *r, char *name, struct stat *st)
127117
int ret = -1;
128118
PRINTF("_stat_r '%s' \n", name);
129119
r->_errno = ENODEV; // no such device
130-
#ifdef MODULE_FAT
131-
ret = ff_stat_r(r, name, st);
132-
#endif
133120
PRINTF("_stat_r [%i] errno %i\n", ret, r->_errno);
134121
return ret;
135122
}
@@ -146,16 +133,7 @@ int _fstat_r(struct _reent *r, int fd, struct stat *st)
146133
ret = 0;
147134
}
148135
else {
149-
150-
#ifdef MODULE_FAT
151-
PRINTF("_fstat_r '%i' \n", fd);
152-
153-
ret = ff_fstat_r(r, fd, st);
154-
PRINTF("_fstat_r [%i] errno %i\n", ret, r->_errno);
155-
156-
#else
157136
r->_errno = ENODEV;
158-
#endif
159137
}
160138

161139
return ret;
@@ -173,9 +151,6 @@ int _write_r(struct _reent *r, int fd, const void *data, unsigned int count)
173151
break;
174152

175153
default:
176-
#ifdef MODULE_FAT
177-
result = ff_write_r(r, fd, data, count);
178-
#endif
179154
PRINTF("write [%i] data @%p count %i\n", fd, data, count);
180155

181156
PRINTF("write [%i] returned %i errno %i\n", fd, result, r->_errno);
@@ -193,9 +168,6 @@ int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count)
193168
(void) count;
194169
int result = -1;
195170
r->_errno = EBADF;
196-
#ifdef MODULE_FAT
197-
result = ff_read_r(r, fd, buffer, count);
198-
#endif
199171
PRINTF("read [%i] buffer @%p count %i\n", fd, buffer, count);
200172
PRINTF("read [%i] returned %i\n", fd, result);
201173

@@ -207,9 +179,6 @@ int _close_r(struct _reent *r, int fd)
207179
(void) fd;
208180
int result = -1;
209181
r->_errno = EBADF;
210-
#ifdef MODULE_FAT
211-
ret = ff_close_r(r, fd);
212-
#endif
213182
PRINTF("close [%i]\n", fd);
214183
PRINTF("close returned %i errno %i\n", result, errno);
215184

@@ -223,9 +192,6 @@ int _unlink_r(struct _reent *r, char *path)
223192

224193
int result = -1;
225194
r->_errno = ENODEV;
226-
#ifdef MODULE_FAT
227-
result = ff_unlink_r(r, path);
228-
#endif
229195
PRINTF("unlink '%s'\n", path);
230196
PRINTF("unlink returned %i errno %i\n", result, errno);
231197

cpu/atmega2560/periph/uart.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "periph/uart.h"
2828
#include "periph_conf.h"
2929

30+
#if UART_0_EN || UART_1_EN || UART2_EN || UART_3_EN
3031

3132
/**
3233
* @brief Each UART device has to store two callbacks.
@@ -315,3 +316,4 @@ ISR(USART2_RX_vect, ISR_BLOCK)
315316
}
316317
}
317318
#endif /* UART_3_EN */
319+
#endif /* UART_0_EN || UART_1_EN |UART_2_EN| UART3 */

cpu/cc430/cc110x_cc430.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ void cc110x_write_reg(uint8_t addr, uint8_t value)
119119

120120
while (!(RFDINIFG & RF1AIFCTL1));
121121

122+
/* cppcheck: need to force a read to RF1ADOUTB to trigger reset */
123+
/* cppcheck-suppress unreadVariable */
122124
i = RF1ADOUTB; /* Reset RFDOUTIFG flag which contains status byte */
123125

124126
restoreIRQ(int_state);
@@ -213,6 +215,8 @@ uint8_t cc110x_writeburst_reg(uint8_t addr, char *buffer, uint8_t count)
213215
while (!(RFDINIFG & RF1AIFCTL1)); /* Wait for TX to finish */
214216
}
215217

218+
/* cppcheck: need to force a read to RF1ADOUTB to trigger reset */
219+
/* cppcheck-suppress unreadVariable */
216220
i = RF1ADOUTB; /* Reset RFDOUTIFG flag which contains status byte */
217221

218222
restoreIRQ(int_state);

cpu/lpc1768/startup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void (* const g_pfnVectors[])(void) =
190190
*******************************************************************************/
191191
void Reset_Handler(void)
192192
{
193-
unsigned long *pulSrc, *pulDest;
193+
unsigned long *pulDest;
194194

195195
/*
196196
* This used for cleaning AHBRAM0 section
@@ -218,7 +218,7 @@ void Reset_Handler(void)
218218
* Copy the data segment initializers from flash to SRAM in ROM mode
219219
*/
220220
#if (__RAM_MODE__==0)
221-
pulSrc = &__sidata;
221+
unsigned long *pulSrc = &__sidata;
222222
for(pulDest = &__data_start__; pulDest < &__data_end__; )
223223
{
224224
*(pulDest++) = *(pulSrc++);

cpu/lpc2387/i2c/i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ bool i2c_read(uint8_t i2c_interface, uint8_t slave_addr, uint8_t reg_addr,
358358
I2C_BUFSIZE * sizeof(uint8_t));
359359
i2c_write_length = 1;
360360
i2c_read_length = rx_buff_length;
361-
bool successful = false;
361+
bool successful;
362362
uint8_t readIndex = 3;
363363
i2c_master_buffer[0] = (slave_addr << 1) & WRITE_ENABLE_BIT_MASK;
364364
i2c_master_buffer[1] = reg_addr;

cpu/mc1322x/maca/maca.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ uint32_t _maca_init_from_flash ( uint32_t addr ) {
10161016
length = buffer[1] & 0x0000ffff;
10171017

10181018
while ( i < ( length-4 ) ) {
1019-
err = nvm_read ( g_nvm_internal_interface_c, type, ( uint8_t * ) buffer, addr+i, 32 );
1019+
nvm_read ( g_nvm_internal_interface_c, type, ( uint8_t * ) buffer, addr+i, 32 );
10201020
i += 4 * _exec_init_entry ( buffer, _ram_values );
10211021
}
10221022
}

cpu/native/syscalls.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,15 @@ void err(int eval, const char *fmt, ...)
320320
va_list argp;
321321
va_start(argp, fmt);
322322
verr(eval, fmt, argp);
323+
va_end(argp);
323324
}
324325

325326
void errx(int eval, const char *fmt, ...)
326327
{
327328
va_list argp;
328329
va_start(argp, fmt);
329330
verrx(eval, fmt, argp);
331+
va_end(argp);
330332
}
331333

332334
int getpid(void)

cpu/nrf51822/periph/uart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "board.h"
3131

3232
/* guard file in case no UART device was specified */
33-
#if UART_NUMOF
33+
#if UART_0_EN
3434

3535
/**
3636
* @brief Each UART device has to store two callbacks.
@@ -241,4 +241,4 @@ void isr_uart0(void)
241241
}
242242
}
243243

244-
#endif /* UART_NUMOF */
244+
#endif /* UART_0_EN */

cpu/samd21/periph/gpio.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ int gpio_init_out(gpio_t dev, gpio_pp_t pushpull)
141141
return -1;
142142
}
143143

144+
if (port == NULL) {
145+
return -1;
146+
}
147+
144148
/* configure as output */
145149
port->DIRSET.reg = (1<<(pin%32));
146150

@@ -264,6 +268,10 @@ int gpio_init_in(gpio_t dev, gpio_pp_t pushpull)
264268
return -1;
265269
}
266270

271+
if (port == NULL) {
272+
return -1;
273+
}
274+
267275
/* configure as input */
268276
port->DIRCLR.reg = (1<<(pin%32));
269277
/* buffer input value */
@@ -411,6 +419,10 @@ int gpio_init_int(gpio_t dev, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb
411419
return -1;
412420
}
413421

422+
if (port == NULL) {
423+
return -1;
424+
}
425+
414426
/* configure pin as input */
415427
res = gpio_init_in(dev, pullup);
416428
if (res < 0) {

cpu/stm32f0/periph/timer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#include "periph_conf.h"
2626
#include "periph/timer.h"
2727

28+
/* guard file in case no TIMER devices are defined */
29+
#if TIMER_0_EN || TIMER_1_EN
30+
2831

2932
static inline void irq_handler(tim_t timer, TIM_TypeDef *dev);
3033

@@ -324,3 +327,4 @@ static inline void irq_handler(tim_t timer, TIM_TypeDef *dev)
324327
config[timer].cb(3);
325328
}
326329
}
330+
#endif /* TIMER_0_EN || TIMER_1_EN */

cpu/stm32f1/periph/i2c.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "debug.h"
3434

3535
/* guard file in case no I2C device is defined */
36-
#if I2C_NUMOF
36+
#if I2C_0_EN
3737

3838
/* static function definitions */
3939
static void _start(I2C_TypeDef *dev, uint8_t address, uint8_t rw_flag);
@@ -392,4 +392,4 @@ static inline void _stop(I2C_TypeDef *dev)
392392
dev->CR1 |= I2C_CR1_STOP;
393393
}
394394

395-
#endif /* I2C_NUMOF */
395+
#endif /* I2C_0_EN */

0 commit comments

Comments
 (0)