1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-16 18:13:49 +01:00

Merge pull request #6703 from OlegHahm/cppcheck_fixes

dist: enable cppcheck warnings for all files
This commit is contained in:
Martine Lenders 2017-04-19 08:18:47 +02:00 committed by GitHub
commit 38f383c68d
36 changed files with 87 additions and 55 deletions

View File

@ -57,6 +57,8 @@ void rtt_init(void)
RTT_UNLOCK(); RTT_UNLOCK();
/* Reset RTC */ /* Reset RTC */
rtt->CR = RTC_CR_SWR_MASK; rtt->CR = RTC_CR_SWR_MASK;
/* cppcheck-suppress redundantAssignment
* reset routine */
rtt->CR = 0; rtt->CR = 0;
if (rtt->SR & RTC_SR_TIF_MASK) { if (rtt->SR & RTC_SR_TIF_MASK) {

View File

@ -6,9 +6,11 @@
* directory for more details. * directory for more details.
*/ */
/*
@-----------------------------------------------------------@ @-----------------------------------------------------------@
@ Fast Block Copy (declared in diskio.h) @ Fast Block Copy (declared in diskio.h)
@-----------------------------------------------------------@ @-----------------------------------------------------------@
*/
.global copy_un2al .global copy_un2al
.arm .arm

View File

@ -76,6 +76,8 @@ void x86_init_gdt(void)
.limit_16_19_and_flags = 0, .limit_16_19_and_flags = 0,
.base_24_31 = 0, .base_24_31 = 0,
}, },
/* cppcheck-suppress duplicateExpression
* it's for consistent look & feel */
[0x0008 / 8] = { [0x0008 / 8] = {
.limit_0_15 = 0xFFFF, .limit_0_15 = 0xFFFF,
.base_0_15 = 0, .base_0_15 = 0,

View File

@ -181,7 +181,7 @@ static void pci_setup_ios(struct x86_known_pci_device *dev)
printf(" BAR %u: memory, physical = 0x%08x-0x%08x, virtual = 0x%08x-0x%08x\n", printf(" BAR %u: memory, physical = 0x%08x-0x%08x, virtual = 0x%08x-0x%08x\n",
bar_num, bar_num,
physical_start, physical_start + length - 1, physical_start, physical_start + length - 1,
(unsigned) ptr, (uintptr_t) ptr + length - 1); (unsigned) ptr, (unsigned) ((uintptr_t) ptr + length - 1));
} }
} }
} }

View File

@ -55,7 +55,7 @@ void x86_pit_set2(unsigned channel, unsigned mode, uint16_t max)
{ {
unsigned old_flags = irq_disable(); unsigned old_flags = irq_disable();
outb(PIT_COMMAND_PORT, ((channel - 1) << 6) | mode | PIT_ACCESS_MODE_LO_HI); outb(PIT_COMMAND_PORT, ((channel - 1) << 6) | mode | PIT_ACCESS_MODE_LO_HI);
outb(PIT_CHANNEL_0_PORT + channel - 1, max && 0xff); outb(PIT_CHANNEL_0_PORT + channel - 1, max & 0xff);
outb(PIT_CHANNEL_0_PORT + channel - 1, max >> 8); outb(PIT_CHANNEL_0_PORT + channel - 1, max >> 8);
irq_restore(old_flags); irq_restore(old_flags);
} }

View File

@ -86,13 +86,7 @@ then
run ./dist/tools/licenses/check.sh ${CI_BASE_BRANCH} --diff-filter=AC run ./dist/tools/licenses/check.sh ${CI_BASE_BRANCH} --diff-filter=AC
run ./dist/tools/doccheck/check.sh ${CI_BASE_BRANCH} run ./dist/tools/doccheck/check.sh ${CI_BASE_BRANCH}
run ./dist/tools/externc/check.sh ${CI_BASE_BRANCH} run ./dist/tools/externc/check.sh ${CI_BASE_BRANCH}
run ./dist/tools/cppcheck/check.sh ${CI_BASE_BRANCH}
# TODO:
# Remove all but `${CI_BASE_BRANCH}` parameters to cppcheck (and remove second
# invocation) once all warnings of cppcheck have been taken care of
# in ${CI_BASE_BRANCH}.
run ./dist/tools/cppcheck/check.sh ${CI_BASE_BRANCH} --diff-filter=MR --error-exitcode=0
run ./dist/tools/cppcheck/check.sh ${CI_BASE_BRANCH} --diff-filter=AC
run ./dist/tools/pr_check/pr_check.sh ${CI_BASE_BRANCH} run ./dist/tools/pr_check/pr_check.sh ${CI_BASE_BRANCH}
exit $RESULT exit $RESULT
fi fi

View File

@ -53,7 +53,6 @@ if [ -z "${FILES}" ]; then
exit exit
fi fi
# TODO: switch back to 8 jobs when/if cppcheck issue is resolved cppcheck --std=c99 --enable=style --force --error-exitcode=2 --quiet -j 8 \
cppcheck --std=c99 --enable=style --force --error-exitcode=2 --quiet -j 1 \
--template "{file}:{line}: {severity} ({id}): {message}" \ --template "{file}:{line}: {severity} ({id}): {message}" \
--inline-suppr ${DEFAULT_SUPPRESSIONS} ${@} ${FILES} --inline-suppr ${DEFAULT_SUPPRESSIONS} ${@} ${FILES}

View File

@ -172,7 +172,6 @@ after_fread:
if (ret == 0) { if (ret == 0) {
clearerr(inslip); clearerr(inslip);
return;
fprintf(stderr, "serial_to_tun: EOF\n"); fprintf(stderr, "serial_to_tun: EOF\n");
exit(1); exit(1);
} }

View File

@ -307,7 +307,7 @@ done:
if (op == DHCP_OPTION_END) { if (op == DHCP_OPTION_END) {
*t++ = op; *t++ = op;
*p++; (*p)++;
} }
optlen = t - pkt.m.options; optlen = t - pkt.m.options;
@ -535,7 +535,6 @@ after_fread:
if (ret == 0) { if (ret == 0) {
clearerr(inslip); clearerr(inslip);
return;
fprintf(stderr, "serial_to_tun: EOF\n"); fprintf(stderr, "serial_to_tun: EOF\n");
exit(1); exit(1);
} }

View File

@ -118,7 +118,6 @@ stamptime(void)
long secs, msecs; long secs, msecs;
struct timeval tv; struct timeval tv;
time_t t; time_t t;
char timec[20];
gettimeofday(&tv, NULL) ; gettimeofday(&tv, NULL) ;
msecs = tv.tv_usec / 1000; msecs = tv.tv_usec / 1000;
@ -136,6 +135,7 @@ stamptime(void)
fprintf(stderr, "%04li.%03li ", secs, msecs); fprintf(stderr, "%04li.%03li ", secs, msecs);
} }
else { else {
char timec[20];
startsecs = secs; startsecs = secs;
startmsecs = msecs; startmsecs = msecs;
t = time(NULL); t = time(NULL);
@ -190,6 +190,8 @@ serial_to_tun(FILE *inslip, int outfd)
unsigned char inbuf[2000]; unsigned char inbuf[2000];
} uip; } uip;
static unsigned int inbufptr = 0; static unsigned int inbufptr = 0;
/* cppcheck-suppress variableScope
* rationale: cannot be reduced if built on linux */
int ret; int ret;
unsigned char c; unsigned char c;
@ -209,7 +211,7 @@ serial_to_tun(FILE *inslip, int outfd)
stamptime(); stamptime();
} }
fprintf(stderr, "*** dropping large %d byte packet\n", inbufptr); fprintf(stderr, "*** dropping large %u byte packet\n", inbufptr);
inbufptr = 0; inbufptr = 0;
} }
@ -324,7 +326,7 @@ serial_to_tun(FILE *inslip, int outfd)
stamptime(); stamptime();
} }
printf("Packet from SLIP of length %d - write TUN\n", inbufptr); printf("Packet from SLIP of length %u - write TUN\n", inbufptr);
if (verbose > 4) { if (verbose > 4) {
#if WIRESHARK_IMPORT_FORMAT #if WIRESHARK_IMPORT_FORMAT
@ -648,6 +650,8 @@ devopen(const char *dev, int flags)
{ {
char t[1024]; char t[1024];
strcpy(t, "/dev/"); strcpy(t, "/dev/");
/* cppcheck-suppress bufferAccessOutOfBounds
* reason: seems to be a cppcheck bug */
strncat(t, dev, sizeof(t) - 5); strncat(t, dev, sizeof(t) - 5);
return open(t, flags); return open(t, flags);
} }
@ -868,10 +872,6 @@ ifconf(const char *tundev, const char *ipaddr)
if (prefix != NULL) { if (prefix != NULL) {
*prefix = '\0'; *prefix = '\0';
prefix++;
}
else {
prefix = "64";
} }
if (timestamp) { if (timestamp) {

View File

@ -218,6 +218,8 @@ float adt7310_read_float(adt7310_t *dev)
{ {
int16_t raw = adt7310_read_raw(dev); int16_t raw = adt7310_read_raw(dev);
if (raw == INT16_MIN) { if (raw == INT16_MIN) {
/* ignore cppcheck: we want to create a NaN here */
/* cppcheck-suppress duplicateExpression */
return (0.0f / 0.0f); /* return NaN */ return (0.0f / 0.0f); /* return NaN */
} }
if (!dev->high_res) { if (!dev->high_res) {

View File

@ -96,7 +96,6 @@ void hdc1000_get_results(hdc1000_t *dev, int16_t *temp, int16_t *hum)
assert(dev); assert(dev);
uint8_t buf[4]; uint8_t buf[4];
uint16_t traw, hraw;
/* first we read the RAW results from the device */ /* first we read the RAW results from the device */
i2c_acquire(dev->p.i2c); i2c_acquire(dev->p.i2c);
@ -105,11 +104,11 @@ void hdc1000_get_results(hdc1000_t *dev, int16_t *temp, int16_t *hum)
/* and finally we convert the values to their physical representation */ /* and finally we convert the values to their physical representation */
if (temp) { if (temp) {
traw = ((uint16_t)buf[0] << 8) | buf[1]; uint16_t traw = ((uint16_t)buf[0] << 8) | buf[1];
*temp = (int16_t)((((int32_t)traw * 16500) >> 16) - 4000); *temp = (int16_t)((((int32_t)traw * 16500) >> 16) - 4000);
} }
if (hum) { if (hum) {
hraw = ((uint16_t)buf[2] << 8) | buf[3]; uint16_t hraw = ((uint16_t)buf[2] << 8) | buf[3];
*hum = (int16_t)(((int32_t)hraw * 10000) >> 16); *hum = (int16_t)(((int32_t)hraw * 10000) >> 16);
} }
} }

View File

@ -73,6 +73,9 @@ static ble_mac_callback_t _callback;
*/ */
static ble_mac_interface_t *ble_mac_interface_lookup(ble_ipsp_handle_t *handle) static ble_mac_interface_t *ble_mac_interface_lookup(ble_ipsp_handle_t *handle)
{ {
if (handle == NULL) {
return NULL;
}
for (int i = 0; i < BLE_MAC_MAX_INTERFACE_NUM; i++) { for (int i = 0; i < BLE_MAC_MAX_INTERFACE_NUM; i++) {
if (interfaces[i].handle.conn_handle == handle->conn_handle && if (interfaces[i].handle.conn_handle == handle->conn_handle &&
interfaces[i].handle.cid == handle->cid) { interfaces[i].handle.cid == handle->cid) {
@ -172,13 +175,12 @@ int ble_mac_send(uint8_t dest[8], void *data, size_t len)
od_hex_dump(data, len, OD_WIDTH_DEFAULT); od_hex_dump(data, len, OD_WIDTH_DEFAULT);
#endif #endif
int i;
ble_ipsp_handle_t *handle; ble_ipsp_handle_t *handle;
int ret = -1; int ret = -1;
if ((!dest) || _is_broadcast(dest)) { if ((!dest) || _is_broadcast(dest)) {
DEBUG("broadcast\n"); DEBUG("broadcast\n");
for (i = 0; i < BLE_MAC_MAX_INTERFACE_NUM; i++) { for (int i = 0; i < BLE_MAC_MAX_INTERFACE_NUM; i++) {
if (interfaces[i].handle.cid != 0 && interfaces[i].handle.conn_handle != 0) { if (interfaces[i].handle.cid != 0 && interfaces[i].handle.conn_handle != 0) {
ret = _send_to_peer(&interfaces[i].handle, data, len); ret = _send_to_peer(&interfaces[i].handle, data, len);
DEBUG("ret=%i\n", ret); DEBUG("ret=%i\n", ret);
@ -207,9 +209,7 @@ static uint32_t ble_mac_ipsp_evt_handler_irq(ble_ipsp_handle_t *p_handle, ble_ip
{ {
uint32_t retval = NRF_SUCCESS; uint32_t retval = NRF_SUCCESS;
ble_mac_interface_t *p_instance = NULL; ble_mac_interface_t *p_instance = ble_mac_interface_lookup(p_handle);
p_instance = ble_mac_interface_lookup(p_handle);
if (p_handle) { if (p_handle) {
DEBUG("ble-mac: IPSP event [handle:%d CID 0x%04X]\n", p_handle->conn_handle, p_handle->cid); DEBUG("ble-mac: IPSP event [handle:%d CID 0x%04X]\n", p_handle->conn_handle, p_handle->cid);

View File

@ -80,9 +80,7 @@ static void _ble_mac_callback(ble_mac_event_enum_t event, void* arg)
static void _handle_raw_sixlowpan(ble_mac_inbuf_t *inbuf) static void _handle_raw_sixlowpan(ble_mac_inbuf_t *inbuf)
{ {
gnrc_pktsnip_t *pkt = NULL; gnrc_pktsnip_t *pkt = gnrc_pktbuf_add(NULL, inbuf->payload,
pkt = gnrc_pktbuf_add(NULL, inbuf->payload,
inbuf->len, inbuf->len,
GNRC_NETTYPE_SIXLOWPAN); GNRC_NETTYPE_SIXLOWPAN);

View File

@ -52,7 +52,7 @@ class time_point {
/** /**
* @brief Create time point from timex_t struct. * @brief Create time point from timex_t struct.
*/ */
inline time_point(timex_t&& tp) : m_handle(tp) {} explicit inline time_point(timex_t&& tp) : m_handle(tp) {}
/** /**
* @brief Use default copy constructor. * @brief Use default copy constructor.
*/ */

View File

@ -27,6 +27,7 @@
#include "time.h" #include "time.h"
#include "thread.h" #include "thread.h"
#include <array>
#include <tuple> #include <tuple>
#include <atomic> #include <atomic>
#include <memory> #include <memory>
@ -65,7 +66,7 @@ struct thread_data {
/** @cond INTERNAL */ /** @cond INTERNAL */
std::atomic<unsigned> ref_count; std::atomic<unsigned> ref_count;
kernel_pid_t joining_thread; kernel_pid_t joining_thread;
char stack[stack_size]; std::array<char, stack_size> stack;
/** @endcond */ /** @endcond */
}; };
@ -106,7 +107,7 @@ public:
/** /**
* @brief Create a thread id from a native handle. * @brief Create a thread id from a native handle.
*/ */
inline thread_id(kernel_pid_t handle) : m_handle{handle} {} explicit inline thread_id(kernel_pid_t handle) : m_handle{handle} {}
/** /**
* @brief Comparison operator for thread ids. * @brief Comparison operator for thread ids.
@ -164,7 +165,7 @@ namespace this_thread {
/** /**
* @brief Access the id of the currently running thread. * @brief Access the id of the currently running thread.
*/ */
inline thread_id get_id() noexcept { return thread_getpid(); } inline thread_id get_id() noexcept { return thread_id{thread_getpid()}; }
/** /**
* @brief Yield the currently running thread. * @brief Yield the currently running thread.
*/ */
@ -286,7 +287,7 @@ public:
/** /**
* @brief Returns the id of a thread. * @brief Returns the id of a thread.
*/ */
inline id get_id() const noexcept { return m_handle; } inline id get_id() const noexcept { return thread_id{m_handle}; }
/** /**
* @brief Returns the native handle to a thread. * @brief Returns the native handle to a thread.
*/ */
@ -345,7 +346,7 @@ thread::thread(F&& f, Args&&... args)
unique_ptr<func_and_args> p( unique_ptr<func_and_args> p(
new func_and_args(m_data.get(), forward<F>(f), forward<Args>(args)...)); new func_and_args(m_data.get(), forward<F>(f), forward<Args>(args)...));
m_handle = thread_create( m_handle = thread_create(
m_data->stack, stack_size, THREAD_PRIORITY_MAIN - 1, 0, m_data->stack.data(), stack_size, THREAD_PRIORITY_MAIN - 1, 0,
&thread_proxy<func_and_args>, p.get(), "riot_cpp_thread"); &thread_proxy<func_and_args>, p.get(), "riot_cpp_thread");
if (m_handle >= 0) { if (m_handle >= 0) {
p.release(); p.release();

View File

@ -53,6 +53,8 @@ static void _doubleround(void *output_, const uint32_t input[16], uint8_t rounds
rounds *= 4; rounds *= 4;
for (unsigned i = 0; i < rounds; ++i) { for (unsigned i = 0; i < rounds; ++i) {
/* cppcheck-suppress duplicateExpressionTernary
* (reason: Externally imported code beautification) */
uint32_t *a = &output[((i + ((i & 4) ? 0 : 0)) & 3) + (4 * 0)]; uint32_t *a = &output[((i + ((i & 4) ? 0 : 0)) & 3) + (4 * 0)];
uint32_t *b = &output[((i + ((i & 4) ? 1 : 0)) & 3) + (4 * 1)]; uint32_t *b = &output[((i + ((i & 4) ? 1 : 0)) & 3) + (4 * 1)];
uint32_t *c = &output[((i + ((i & 4) ? 2 : 0)) & 3) + (4 * 2)]; uint32_t *c = &output[((i + ((i & 4) ? 2 : 0)) & 3) + (4 * 2)];

View File

@ -58,7 +58,7 @@ int cipher_decrypt_cbc(cipher_t* cipher, uint8_t iv[16],
uint8_t* input, size_t length, uint8_t* output) uint8_t* input, size_t length, uint8_t* output)
{ {
size_t offset = 0; size_t offset = 0;
uint8_t* input_block, *output_block, *input_block_last, block_size; uint8_t* input_block, *input_block_last, block_size;
block_size = cipher_get_block_size(cipher); block_size = cipher_get_block_size(cipher);
@ -69,7 +69,7 @@ int cipher_decrypt_cbc(cipher_t* cipher, uint8_t iv[16],
input_block_last = iv; input_block_last = iv;
do { do {
input_block = input + offset; input_block = input + offset;
output_block = output + offset; uint8_t *output_block = output + offset;
if (cipher_decrypt(cipher, input_block, output_block) != 1) { if (cipher_decrypt(cipher, input_block, output_block) != 1) {
return CIPHER_ERR_DEC_FAILED; return CIPHER_ERR_DEC_FAILED;

View File

@ -51,6 +51,8 @@ static inline uint32_t _xtimer_lltimer_now(void)
*/ */
static inline uint32_t _xtimer_lltimer_mask(uint32_t val) static inline uint32_t _xtimer_lltimer_mask(uint32_t val)
{ {
/* cppcheck-suppress shiftTooManyBits
* (reason: cppcheck bug. `XTIMER_MASK` is zero when `XTIMER_WIDTH` is 32) */
return val & ~XTIMER_MASK; return val & ~XTIMER_MASK;
} }

View File

@ -93,7 +93,7 @@ int conn_udp_sendto(const void *data, size_t len, const void *src, size_t src_le
const void *dst, size_t dst_len, int family, uint16_t sport, const void *dst, size_t dst_len, int family, uint16_t sport,
uint16_t dport) uint16_t dport)
{ {
gnrc_pktsnip_t *pkt, *hdr = NULL; gnrc_pktsnip_t *pkt, *hdr;
pkt = gnrc_pktbuf_add(NULL, (void *)data, len, GNRC_NETTYPE_UNDEF); /* data will only be copied */ pkt = gnrc_pktbuf_add(NULL, (void *)data, len, GNRC_NETTYPE_UNDEF); /* data will only be copied */
hdr = gnrc_udp_hdr_build(pkt, sport, dport); hdr = gnrc_udp_hdr_build(pkt, sport, dport);

View File

@ -792,6 +792,8 @@ void gnrc_ipv6_netif_init_by_dev(void)
kernel_pid_t ifs[GNRC_NETIF_NUMOF]; kernel_pid_t ifs[GNRC_NETIF_NUMOF];
size_t ifnum = gnrc_netif_get(ifs); size_t ifnum = gnrc_netif_get(ifs);
#ifdef MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER #ifdef MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER
/* cppcheck-suppress unreadVariable
* (reason: cppcheck bug. abr_init is read in if below) */
bool abr_init = false; bool abr_init = false;
#endif #endif

View File

@ -672,6 +672,8 @@ void gnrc_ndp_retrans_nbr_sol(gnrc_ipv6_nc_t *nc_entry)
mutex_unlock(&ipv6_iface->mutex); mutex_unlock(&ipv6_iface->mutex);
} }
} }
/* cppcheck-suppress knownConditionTrueFalse
* cppcheck bug: probes_remaining is initialized to a value > 1 */
else if (nc_entry->probes_remaining <= 1) { else if (nc_entry->probes_remaining <= 1) {
/* For a 6LoWPAN router entries may be set to UNREACHABLE instead /* For a 6LoWPAN router entries may be set to UNREACHABLE instead

View File

@ -80,6 +80,8 @@ kernel_pid_t gnrc_ndp_node_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_len,
} }
#endif #endif
/* cppcheck-suppress knownConditionTrueFalse
* cppcheck bug: next_hop_ip might be initialized if a FIB is available */
if (next_hop_ip == NULL) { /* no route to host */ if (next_hop_ip == NULL) { /* no route to host */
if (!dst_link_local) { if (!dst_link_local) {
if (iface == KERNEL_PID_UNDEF) { if (iface == KERNEL_PID_UNDEF) {

View File

@ -128,7 +128,7 @@ kernel_pid_t gnrc_sixlowpan_nd_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_
kernel_pid_t fib_iface; kernel_pid_t fib_iface;
ipv6_addr_t next_hop_actual; /* FIB copies address into this variable */ ipv6_addr_t next_hop_actual; /* FIB copies address into this variable */
/* don't look-up link local addresses in FIB */ /* don't look-up link local addresses in FIB */
if ((next_hop == NULL) && !ipv6_addr_is_link_local(dst)) { if (!ipv6_addr_is_link_local(dst)) {
size_t next_hop_size = sizeof(ipv6_addr_t); size_t next_hop_size = sizeof(ipv6_addr_t);
uint32_t next_hop_flags = 0; uint32_t next_hop_flags = 0;
if ((next_hop == NULL) && if ((next_hop == NULL) &&
@ -142,6 +142,8 @@ kernel_pid_t gnrc_sixlowpan_nd_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_
#endif #endif
#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER #ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER
/* next hop determination: https://tools.ietf.org/html/rfc6775#section-6.5.4 */ /* next hop determination: https://tools.ietf.org/html/rfc6775#section-6.5.4 */
/* cppcheck-suppress redundantAssignment
* This path is only present for a certain configuration */
nc_entry = gnrc_ipv6_nc_get(iface, dst); nc_entry = gnrc_ipv6_nc_get(iface, dst);
#ifdef MODULE_FIB #ifdef MODULE_FIB
if ((next_hop != NULL) && (nc_entry == NULL)) { if ((next_hop != NULL) && (nc_entry == NULL)) {
@ -161,6 +163,8 @@ kernel_pid_t gnrc_sixlowpan_nd_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_
} }
#endif #endif
/* next hop determination according to: https://tools.ietf.org/html/rfc6775#section-5.6 */ /* next hop determination according to: https://tools.ietf.org/html/rfc6775#section-5.6 */
/* cppcheck-suppress knownConditionTrueFalse
* cppcheck bug: next_hop might be set before */
if ((next_hop == NULL) && ipv6_addr_is_link_local(dst)) { /* prefix is "on-link" */ if ((next_hop == NULL) && ipv6_addr_is_link_local(dst)) { /* prefix is "on-link" */
/* multicast is not handled here anyway so we don't need to check that */ /* multicast is not handled here anyway so we don't need to check that */
next_hop = dst; next_hop = dst;
@ -175,6 +179,8 @@ kernel_pid_t gnrc_sixlowpan_nd_next_hop_l2addr(uint8_t *l2addr, uint8_t *l2addr_
} }
/* address resolution of next_hop: https://tools.ietf.org/html/rfc6775#section-5.7 */ /* address resolution of next_hop: https://tools.ietf.org/html/rfc6775#section-5.7 */
/* cppcheck-suppress knownConditionTrueFalse
* cppcheck bug: nc_entry might be set before */
if ((nc_entry == NULL) || (next_hop != dst)) { if ((nc_entry == NULL) || (next_hop != dst)) {
/* get if not gotten from previous check */ /* get if not gotten from previous check */
nc_entry = gnrc_ipv6_nc_get(iface, next_hop); nc_entry = gnrc_ipv6_nc_get(iface, next_hop);

View File

@ -48,9 +48,8 @@ const uint8_t gnrc_rpl_p2p_lifetime_lookup[4] = { 1, 4, 16, 64 };
void gnrc_rpl_p2p_update(void) void gnrc_rpl_p2p_update(void)
{ {
gnrc_rpl_p2p_ext_t *p2p_ext;
for (uint8_t i = 0; i < GNRC_RPL_P2P_EXTS_NUMOF; ++i) { for (uint8_t i = 0; i < GNRC_RPL_P2P_EXTS_NUMOF; ++i) {
p2p_ext = &gnrc_rpl_p2p_exts[i]; gnrc_rpl_p2p_ext_t *p2p_ext = &gnrc_rpl_p2p_exts[i];
if ((p2p_ext->state) && (p2p_ext->lifetime_sec > 0)) { if ((p2p_ext->state) && (p2p_ext->lifetime_sec > 0)) {
p2p_ext->lifetime_sec -= GNRC_RPL_LIFETIME_UPDATE_STEP; p2p_ext->lifetime_sec -= GNRC_RPL_LIFETIME_UPDATE_STEP;
if (p2p_ext->lifetime_sec <= 0) { if (p2p_ext->lifetime_sec <= 0) {

View File

@ -69,10 +69,9 @@ static bool _dyn_port_used(uint16_t port)
*/ */
static uint16_t _get_dyn_port(sock_udp_t *sock) static uint16_t _get_dyn_port(sock_udp_t *sock)
{ {
uint16_t port;
unsigned count = GNRC_SOCK_DYN_PORTRANGE_NUM; unsigned count = GNRC_SOCK_DYN_PORTRANGE_NUM;
do { do {
port = GNRC_SOCK_DYN_PORTRANGE_MIN + uint16_t port = GNRC_SOCK_DYN_PORTRANGE_MIN +
(_dyn_port_next * GNRC_SOCK_DYN_PORTRANGE_OFF) % GNRC_SOCK_DYN_PORTRANGE_NUM; (_dyn_port_next * GNRC_SOCK_DYN_PORTRANGE_OFF) % GNRC_SOCK_DYN_PORTRANGE_NUM;
_dyn_port_next++; _dyn_port_next++;
if ((sock == NULL) || (sock->flags & SOCK_FLAGS_REUSE_EP) || if ((sock == NULL) || (sock->flags & SOCK_FLAGS_REUSE_EP) ||

View File

@ -97,7 +97,7 @@ quad_t __muldi3(quad_t a, quad_t b)
{ {
union uu u, v, low, prod; union uu u, v, low, prod;
u_int high, mid, udiff, vdiff; u_int high, mid, udiff, vdiff;
int negall, negmid; int negall;
#define u1 u.ul[H] #define u1 u.ul[H]
#define u0 u.ul[L] #define u0 u.ul[L]
#define v1 v.ul[H] #define v1 v.ul[H]
@ -131,6 +131,7 @@ quad_t __muldi3(quad_t a, quad_t b)
prod.q = __lmulq(u0, v0); prod.q = __lmulq(u0, v0);
} }
else { else {
int negmid;
/* /*
* Compute the three intermediate products, remembering * Compute the three intermediate products, remembering
* whether the middle term is negative. We can discard * whether the middle term is negative. We can discard

View File

@ -78,6 +78,8 @@ __qdivrem(u_quad_t uq, u_quad_t vq, u_quad_t *arq)
/* divide by zero. */ /* divide by zero. */
static volatile const unsigned int zero = 0; static volatile const unsigned int zero = 0;
/* cppcheck-suppress zerodiv
* Divission by zero is on purpose here */
tmp.ul[H] = tmp.ul[L] = 1 / zero; tmp.ul[H] = tmp.ul[L] = 1 / zero;
if (arq) { if (arq) {

View File

@ -31,9 +31,8 @@
int _gnrc_rpl_init(char *arg) int _gnrc_rpl_init(char *arg)
{ {
gnrc_ipv6_netif_t *entry = NULL;
kernel_pid_t iface_pid = (kernel_pid_t) atoi(arg); kernel_pid_t iface_pid = (kernel_pid_t) atoi(arg);
entry = gnrc_ipv6_netif_get(iface_pid); gnrc_ipv6_netif_t *entry = gnrc_ipv6_netif_get(iface_pid);
if (entry == NULL) { if (entry == NULL) {
puts("unknown interface specified"); puts("unknown interface specified");
@ -55,8 +54,7 @@ int _gnrc_rpl_dodag_root(char *arg1, char *arg2)
return 1; return 1;
} }
gnrc_rpl_instance_t *inst = NULL; gnrc_rpl_instance_t *inst = gnrc_rpl_root_init(instance_id, &dodag_id, false, false);
inst = gnrc_rpl_root_init(instance_id, &dodag_id, false, false);
if (inst == NULL) { if (inst == NULL) {
char addr_str[IPV6_ADDR_MAX_STR_LEN]; char addr_str[IPV6_ADDR_MAX_STR_LEN];
printf("error: could not add DODAG (%s) to instance (%d)\n", printf("error: could not add DODAG (%s) to instance (%d)\n",

View File

@ -72,6 +72,9 @@ static mutex_t mtx_access = MUTEX_INIT;
*/ */
static universal_address_container_t *universal_address_find_entry(uint8_t *addr, size_t addr_size) static universal_address_container_t *universal_address_find_entry(uint8_t *addr, size_t addr_size)
{ {
/* cppcheck-suppress unsignedLessThanZero
* (reason: UNIVERSAL_ADDRESS_MAX_ENTRIES may be zero in which case this
* code is optimized out) */
for (size_t i = 0; i < UNIVERSAL_ADDRESS_MAX_ENTRIES; ++i) { for (size_t i = 0; i < UNIVERSAL_ADDRESS_MAX_ENTRIES; ++i) {
if (universal_address_table[i].address_size == addr_size) { if (universal_address_table[i].address_size == addr_size) {
if (memcmp((universal_address_table[i].address), addr, addr_size) == 0) { if (memcmp((universal_address_table[i].address), addr, addr_size) == 0) {
@ -91,7 +94,11 @@ static universal_address_container_t *universal_address_find_entry(uint8_t *addr
*/ */
static universal_address_container_t *universal_address_get_next_unused_entry(void) static universal_address_container_t *universal_address_get_next_unused_entry(void)
{ {
/* cppcheck-suppress unsignedLessThanZero
* (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) { if (universal_address_table_filled < UNIVERSAL_ADDRESS_MAX_ENTRIES) {
/* cppcheck-suppress unsignedLessThanZero */
for (size_t i = 0; i < UNIVERSAL_ADDRESS_MAX_ENTRIES; ++i) { for (size_t i = 0; i < UNIVERSAL_ADDRESS_MAX_ENTRIES; ++i) {
if (universal_address_table[i].use_count == 0) { if (universal_address_table[i].use_count == 0) {
return &(universal_address_table[i]); return &(universal_address_table[i]);
@ -294,6 +301,9 @@ void universal_address_init(void)
{ {
mutex_lock(&mtx_access); mutex_lock(&mtx_access);
/* cppcheck-suppress unsignedLessThanZero
* (reason: UNIVERSAL_ADDRESS_MAX_ENTRIES may be zero in which case this
* code is optimized out) */
for (size_t i = 0; i < UNIVERSAL_ADDRESS_MAX_ENTRIES; ++i) { for (size_t i = 0; i < UNIVERSAL_ADDRESS_MAX_ENTRIES; ++i) {
universal_address_table[i].use_count = 0; universal_address_table[i].use_count = 0;
universal_address_table[i].address_size = 0; universal_address_table[i].address_size = 0;
@ -307,6 +317,9 @@ void universal_address_reset(void)
{ {
mutex_lock(&mtx_access); mutex_lock(&mtx_access);
/* cppcheck-suppress unsignedLessThanZero
* (reason: UNIVERSAL_ADDRESS_MAX_ENTRIES may be zero in which case this
* code is optimized out) */
for (size_t i = 0; i < UNIVERSAL_ADDRESS_MAX_ENTRIES; ++i) { for (size_t i = 0; i < UNIVERSAL_ADDRESS_MAX_ENTRIES; ++i) {
universal_address_table[i].use_count = 0; universal_address_table[i].use_count = 0;
} }
@ -348,6 +361,9 @@ void universal_address_print_table(void)
printf("[universal_address_print_table] universal_address_table_filled: %d\n", \ printf("[universal_address_print_table] universal_address_table_filled: %d\n", \
(int)universal_address_table_filled); (int)universal_address_table_filled);
/* cppcheck-suppress unsignedLessThanZero
* (reason: UNIVERSAL_ADDRESS_MAX_ENTRIES may be zero in which case this
* code is optimized out) */
for (size_t i = 0; i < UNIVERSAL_ADDRESS_MAX_ENTRIES; ++i) { for (size_t i = 0; i < UNIVERSAL_ADDRESS_MAX_ENTRIES; ++i) {
universal_address_print_entry(&universal_address_table[i]); universal_address_print_entry(&universal_address_table[i]);
} }

View File

@ -33,7 +33,6 @@ int main(void)
{ {
hdc1000_t dev; hdc1000_t dev;
int16_t temp, hum; int16_t temp, hum;
size_t len;
char tstr[8]; char tstr[8];
char hstr[8]; char hstr[8];
@ -49,6 +48,7 @@ int main(void)
} }
while (1) { while (1) {
size_t len;
hdc1000_read(&dev, &temp, &hum); hdc1000_read(&dev, &temp, &hum);
len = fmt_s16_dfp(tstr, temp, 2); len = fmt_s16_dfp(tstr, temp, 2);

View File

@ -50,6 +50,8 @@ int main(void)
ret = pn532_init_i2c(&pn532, &pn532_conf[0]); ret = pn532_init_i2c(&pn532, &pn532_conf[0]);
#elif defined(PN532_SUPPORT_SPI) #elif defined(PN532_SUPPORT_SPI)
ret = pn532_init_spi(&pn532, &pn532_conf[0]); ret = pn532_init_spi(&pn532, &pn532_conf[0]);
#else
#error None of PN532_SUPPORT_I2C and PN532_SUPPORT_SPI set!
#endif #endif
if (ret != 0) { if (ret != 0) {

View File

@ -77,6 +77,8 @@ int main(void)
#endif #endif
puts("On-board LED test\n"); puts("On-board LED test\n");
/* cppcheck-suppress knownConditionTrueFalse
* rationale: board-dependent ifdefs */
if (numof == 0) { if (numof == 0) {
puts("NO LEDs AVAILABLE"); puts("NO LEDs AVAILABLE");
} }

View File

@ -31,7 +31,7 @@ int main(void)
uint8_t buf[LIMIT]; uint8_t buf[LIMIT];
puts("\nHWRNG peripheral driver test\n"); puts("\nHWRNG peripheral driver test\n");
printf("This test will print from 1 to %i random bytes about every " printf("This test will print from 1 to %u random bytes about every "
"second\n\n", LIMIT); "second\n\n", LIMIT);
puts("Initializing the HWRNG driver.\n"); puts("Initializing the HWRNG driver.\n");

View File

@ -68,7 +68,7 @@ int main(void) {
void *res; void *res;
pthread_join(th_id, (void **) &res); pthread_join(th_id, (void **) &res);
printf("Result: %u\n", (int) (intptr_t) res); printf("Result: %i\n", (int) (intptr_t) res);
puts("Done."); puts("Done.");
return 0; return 0;
} }

View File

@ -40,7 +40,7 @@ void tests_crypto(void);
*/ */
Test *tests_crypto_chacha_tests(void); Test *tests_crypto_chacha_tests(void);
static inline int compare(uint8_t a[16], uint8_t b[16], uint8_t len) static inline int compare(uint8_t *a, uint8_t *b, uint8_t len)
{ {
int result = 1; int result = 1;