diff --git a/core/clist.c b/core/clist.c index 1e7db162699207272fa8c3de6658187dbbdc6380..c776d64f7b443069977b160d4ae8d24926049810 100644 --- a/core/clist.c +++ b/core/clist.c @@ -78,6 +78,8 @@ clist_node_t *_clist_sort(clist_node_t *list, clist_cmp_func_t cmp) for (i = 0; i < insize; i++) { psize++; q = (q->next == oldhead) ? NULL : q->next; + /* cppcheck-suppress nullPointer + * (reason: possible bug in cppcheck 1.6x) */ if (!q) { break; } @@ -134,7 +136,8 @@ clist_node_t *_clist_sort(clist_node_t *list, clist_cmp_func_t cmp) p = q; } - /* cppcheck-suppress nullPointer */ + /* cppcheck-suppress nullPointer + * (reason: tail cannot be NULL at this point, because list != NULL) */ tail->next = list; /* If we have done only one merge, we're finished. */ diff --git a/cpu/cortexm_common/vectors_cortexm.c b/cpu/cortexm_common/vectors_cortexm.c index 25b9cf18cbc558645b792357450b1685a87991d5..3bf56daa509c099935d2521ed0ace3fd828ebb16 100644 --- a/cpu/cortexm_common/vectors_cortexm.c +++ b/cpu/cortexm_common/vectors_cortexm.c @@ -237,7 +237,7 @@ __attribute__((used)) void hard_fault_handler(uint32_t* sp, uint32_t corrupted, * Fixes wrong compiler warning by gcc < 6.0. */ uint32_t pc = 0; /* cppcheck-suppress variableScope - * variable used in assembly-code below */ + * (reason: used within __asm__ which cppcheck doesn't pick up) */ uint32_t* orig_sp = NULL; /* Check if the ISR stack overflowed previously. Not possible to detect diff --git a/cpu/fe310/periph/uart.c b/cpu/fe310/periph/uart.c index 675d34f4e81f533ccde95bc79b5239a6ae8ca8dc..dbc0182d77f6ad91318c66040f8c871d2ca6500c 100644 --- a/cpu/fe310/periph/uart.c +++ b/cpu/fe310/periph/uart.c @@ -80,7 +80,8 @@ int uart_init(uart_t dev, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) /* Calculate buadrate divisor given current CPU clk rate * Ignore the first run (icache needs to be warm) */ uartDiv = PRCI_measure_mcycle_freq(1000, RTC_FREQ); - /* cppcheck-suppress redundantAssignment */ + /* cppcheck-suppress redundantAssignment + * (reason: should ignore first cycle to get correct values) */ uartDiv = PRCI_measure_mcycle_freq(1000, RTC_FREQ); uartDiv = uartDiv / baudrate; diff --git a/cpu/kinetis/periph/i2c.c b/cpu/kinetis/periph/i2c.c index 64d14c6d26bd08672601c583afffe34a6716b023..2e5eeb0f782076d37b3ed2a00d5e701416855e95 100644 --- a/cpu/kinetis/periph/i2c.c +++ b/cpu/kinetis/periph/i2c.c @@ -170,7 +170,7 @@ static uint8_t i2c_find_divider(unsigned freq, unsigned speed) static inline void i2c_clear_irq_flags(I2C_Type *i2c) { /* cppcheck-suppress selfAssignment - * reason: intentional self assignment to clear all pending IRQs */ + * (reason: intentional self assignment to clear all pending IRQs) */ i2c->S = i2c->S; } diff --git a/cpu/kinetis/periph/timer.c b/cpu/kinetis/periph/timer.c index 1f6edbdeb7b47ba1de63a66be6faa5aaab46764e..021c6bee3ea6fa8ac3582d5ceb76ba5e27b7f28a 100644 --- a/cpu/kinetis/periph/timer.c +++ b/cpu/kinetis/periph/timer.c @@ -436,7 +436,7 @@ static inline int lptmr_set(uint8_t dev, uint16_t timeout) hw->CNR = 0; hw->CMR = timeout + hw->CNR; /* cppcheck-suppress selfAssignment - * Clear IRQ flags */ + * (reason: intentional self assignment to clear all pending IRQs) */ hw->CSR = hw->CSR; /* Enable timer and IRQ */ hw->CSR = LPTMR_CSR_TEN_MASK | LPTMR_CSR_TFC_MASK | LPTMR_CSR_TIE_MASK; @@ -469,7 +469,7 @@ static inline int lptmr_set_absolute(uint8_t dev, uint16_t target) /* TCF is set, safe to update CMR live */ hw->CMR = target - lptmr[dev].cnr; /* cppcheck-suppress selfAssignment - * Clear IRQ flags */ + * (reason: intentional self assignment to clear all pending IRQs) */ hw->CSR = hw->CSR; /* Enable timer and IRQ */ hw->CSR = LPTMR_CSR_TEN_MASK | LPTMR_CSR_TFC_MASK | LPTMR_CSR_TIE_MASK; diff --git a/cpu/mips32r2_common/newlib_syscalls_mips_uhi/syscalls.c b/cpu/mips32r2_common/newlib_syscalls_mips_uhi/syscalls.c index 3f0d7e49a6b0670e628223a0d3975039581fe5e2..87efbb0c575020ed198d08c164f3d3ff3d085e28 100644 --- a/cpu/mips32r2_common/newlib_syscalls_mips_uhi/syscalls.c +++ b/cpu/mips32r2_common/newlib_syscalls_mips_uhi/syscalls.c @@ -69,11 +69,8 @@ void _exit(int n) { exit(n); - /* - * Disable unreachableCode cppcheck as pm_off spins indefinately after - * pulling the plug - */ - /* cppcheck-suppress unreachableCode */ + /* cppcheck-suppress unreachableCode + * (reason: pm_off spins indefinately after pulling the plug) */ pm_off(); } diff --git a/dist/tools/cppcheck/README.md b/dist/tools/cppcheck/README.md index ee8ee186f3b42fcb13dc197f0ed7bfea67fb518a..bbbae371abcfb695a30ce7098309d8688b4df5c5 100644 --- a/dist/tools/cppcheck/README.md +++ b/dist/tools/cppcheck/README.md @@ -33,7 +33,9 @@ you want to get warnings about "unusedStructMembers" run the script with the You should read the code carefully. While cppcheck certainly produces valuable information, it can also warn about code that is actually OK. -If this happens, you can add an "inline suppression" like this: +If this happens, you can add an "inline suppression" and briefly state +why this is required like this: - /* cppcheck-suppress passedByValue */ + /* cppcheck-suppress passedByValue + * (reason: <add rationale on why it is necessary to suppress this here>) */ timex_t timex_add(const timex_t a, const timex_t b); diff --git a/dist/tools/tunslip/tunslip6.c b/dist/tools/tunslip/tunslip6.c index 67ad3a0d5cc051040009d31a8a7f4419224690b9..19c9074273841dd3701b77c6975e4b16cd60fa39 100644 --- a/dist/tools/tunslip/tunslip6.c +++ b/dist/tools/tunslip/tunslip6.c @@ -191,7 +191,7 @@ serial_to_tun(FILE *inslip, int outfd) } uip; static unsigned int inbufptr = 0; /* cppcheck-suppress variableScope - * rationale: cannot be reduced if built on linux */ + * (reason: cannot be reduced if built on linux) */ int ret; unsigned char c; @@ -651,7 +651,7 @@ devopen(const char *dev, int flags) char t[1024]; strcpy(t, "/dev/"); /* cppcheck-suppress bufferAccessOutOfBounds - * reason: seems to be a cppcheck bug */ + * (reason: seems to be a bug in cppcheck 1.7x) */ strncat(t, dev, sizeof(t) - 5); return open(t, flags); } diff --git a/drivers/adt7310/adt7310.c b/drivers/adt7310/adt7310.c index 8af6ad770747f705dbc378ee12641f16ad8e5440..1cd5aabfc007abf310e70de4fe9fd6a574a89233 100644 --- a/drivers/adt7310/adt7310.c +++ b/drivers/adt7310/adt7310.c @@ -218,8 +218,8 @@ float adt7310_read_float(const adt7310_t *dev) { int16_t raw = adt7310_read_raw(dev); if (raw == INT16_MIN) { - /* ignore cppcheck: we want to create a NaN here */ - /* cppcheck-suppress duplicateExpression */ + /* cppcheck-suppress duplicateExpression + * (reason: we want to create a NaN here) */ return (0.0f / 0.0f); /* return NaN */ } if (!dev->high_res) { diff --git a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_eventloop.c b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_eventloop.c index e8d8acce57b9bb4b99f2d29c14b6a9731305c384..db7fb5621c26823f348fc3e396b46406ad9b73f4 100644 --- a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_eventloop.c +++ b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_eventloop.c @@ -55,7 +55,8 @@ static int _send(gnrc_pktsnip_t *pkt) /* Search for TCP header */ LL_SEARCH_SCALAR(pkt, tcp, type, GNRC_NETTYPE_TCP); - /* cppcheck-suppress knownConditionTrueFalse */ + /* cppcheck-suppress knownConditionTrueFalse + * (reason: tcp *can* be != NULL after LL_SEARCH_SCALAR) */ if (tcp == NULL) { DEBUG("gnrc_tcp_eventloop : _send() : tcp header missing.\n"); gnrc_pktbuf_release(pkt); diff --git a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_fsm.c b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_fsm.c index ffa8ad959560056ef4729d100462ff1e4d3a3dc7..3a8ffe3e1887a863b75f97aa0a2ea0e671ebce8b 100644 --- a/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_fsm.c +++ b/sys/net/gnrc/transport_layer/tcp/gnrc_tcp_fsm.c @@ -482,7 +482,8 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t *in_pkt) if (ipv6_addr_is_link_local((ipv6_addr_t *) tcb->peer_addr)) { gnrc_pktsnip_t *tmp = NULL; LL_SEARCH_SCALAR(in_pkt, tmp, type, GNRC_NETTYPE_NETIF); - /* cppcheck-suppress knownConditionTrueFalse */ + /* cppcheck-suppress knownConditionTrueFalse + * (reason: tmp *can* be != NULL after LL_SEARCH_SCALAR) */ if (tmp == NULL) { DEBUG("gnrc_tcp_fsm.c : _fsm_rcvd_pkt() :\ incomming packet had no netif header\n"); diff --git a/sys/quad_math/qdivrem.c b/sys/quad_math/qdivrem.c index 8ff7ecb15b241757f53c1c2940b7c808928a2068..b4d7940f953d37044966faf635e75aeee47d084c 100644 --- a/sys/quad_math/qdivrem.c +++ b/sys/quad_math/qdivrem.c @@ -79,7 +79,7 @@ __qdivrem(u_quad_t uq, u_quad_t vq, u_quad_t *arq) static volatile const unsigned int zero = 0; /* cppcheck-suppress zerodiv - * Divission by zero is on purpose here */ + * (reason: division by zero is on purpose here) */ tmp.ul[H] = tmp.ul[L] = 1 / zero; if (arq) { diff --git a/sys/universal_address/universal_address.c b/sys/universal_address/universal_address.c index b581c9d302fc2dec7697bf2f741b4f832e57bdb7..56e4a292f1494cb50ed5b67137aca3ac1901624d 100644 --- a/sys/universal_address/universal_address.c +++ b/sys/universal_address/universal_address.c @@ -98,7 +98,8 @@ static universal_address_container_t *universal_address_get_next_unused_entry(vo * (reason: UNIVERSAL_ADDRESS_MAX_ENTRIES may be zero in which case this * code is optimized out) */ if (universal_address_table_filled < UNIVERSAL_ADDRESS_MAX_ENTRIES) { - /* cppcheck-suppress unsignedLessThanZero */ + /* cppcheck-suppress unsignedLessThanZero + * (reason: UNIVERSAL_ADDRESS_MAX_ENTRIES may be zero, see above) */ for (size_t i = 0; i < UNIVERSAL_ADDRESS_MAX_ENTRIES; ++i) { if (universal_address_table[i].use_count == 0) { return &(universal_address_table[i]); diff --git a/tests/buttons/main.c b/tests/buttons/main.c index de18b9528dac4c1d453e67578bc5900656a1c7a5..6946ce728a1300363d4e21a934ef96fc01d12d06 100644 --- a/tests/buttons/main.c +++ b/tests/buttons/main.c @@ -69,7 +69,7 @@ int main(void) puts("On-board button test\n"); /* cppcheck-suppress knownConditionTrueFalse - * rationale: board-dependent ifdefs */ + * (reason: board-dependent ifdefs) */ if (cnt == 0) { puts("[FAILED] no buttons available!"); return 2; diff --git a/tests/cpp11_condition_variable/main.cpp b/tests/cpp11_condition_variable/main.cpp index 7a1cff84e5e7144e9ae837020a87bd038c60b6e5..035190ed1d4632189f6d639582e564f3f4079c13 100644 --- a/tests/cpp11_condition_variable/main.cpp +++ b/tests/cpp11_condition_variable/main.cpp @@ -53,7 +53,7 @@ int main() { { lock_guard<mutex> lk(m); /* cppcheck-suppress unreadVariable - * (reason variable is read in the thread created above) */ + * (reason: variable is read in the thread created above) */ ready = true; cv.notify_one(); } diff --git a/tests/leds/main.c b/tests/leds/main.c index fc329a8146bfc55a45d939fd506ce5514e55b011..8ff384870fef5e9ee78b92e404f8b9b2f9a790c7 100644 --- a/tests/leds/main.c +++ b/tests/leds/main.c @@ -78,7 +78,7 @@ int main(void) puts("On-board LED test\n"); /* cppcheck-suppress knownConditionTrueFalse - * rationale: board-dependent ifdefs */ + * (reason: board-dependent ifdefs) */ if (numof == 0) { puts("NO LEDs AVAILABLE"); }