Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dist/tools/cppcheck: fix all Cppcheck 1.82 errors #12764

Merged
merged 12 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpu/lpc1768/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void isr_eint3(void)

/* invoke all handlers */
for (int i = 0; i < NUMOF_IRQS; i++) {
if (status & (1 << i)) {
if (status & ((uint32_t)1 << i)) {
isr_ctx[i].cb(isr_ctx[i].arg);

LPC_GPIOINT->IO0IntClr |= (1 << i);
Expand Down
2 changes: 1 addition & 1 deletion cpu/native/irq_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ int irq_is_in(void)
int _native_popsig(void)
{
int nread, nleft, i;
int sig;
int sig = 0;

nleft = sizeof(int);
i = 0;
Expand Down
2 changes: 1 addition & 1 deletion cpu/sam3/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ static inline void isr_handler(Pio *port, int port_num)
uint32_t status = (port->PIO_ISR & port->PIO_IMR);

for (int i = 0; i < 32; i++) {
if (status & (1 << i)) {
if (status & ((uint32_t)1 << i)) {
int ctx = _ctx(port_num, i);
exti_ctx[ctx].cb(exti_ctx[ctx].arg);
}
Expand Down
2 changes: 0 additions & 2 deletions dist/tools/ethos/ethos.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,13 @@ static void _write_escaped(int fd, char* buf, ssize_t n)
/* Our workaround is to prepare the data to send in a local buffer and then
* call write() on the buffer instead of one char at a time */
uint8_t out[SERIAL_BUFFER_SIZE];
size_t escaped = 0;
size_t buffered = 0;

while(n--) {
unsigned char c = *buf++;
if (c == LINE_FRAME_DELIMITER || c == LINE_ESC_CHAR) {
out[buffered++] = LINE_ESC_CHAR;
c ^= 0x20;
++escaped;
if (buffered >= SERIAL_BUFFER_SIZE) {
checked_write(fd, out, buffered);
buffered = 0;
Expand Down
2 changes: 1 addition & 1 deletion pkg/u8g2/src/csrc/u8g2_riotos.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static void u8x8_enable_pins(gpio_t* pins, uint32_t pins_enabled)
uint8_t i;

for (i = 0; i < 32; i++) {
if (pins_enabled & (1 << i)) {
if (pins_enabled & ((uint32_t)1 << i)) {
if (pins[i] != GPIO_UNDEF) {
if (i < U8X8_PIN_OUTPUT_CNT) {
gpio_init(pins[i], GPIO_OUT);
Expand Down
2 changes: 1 addition & 1 deletion pkg/ucglib/src/csrc/ucg_riotos.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void ucg_enable_pins(gpio_t *pins, uint32_t pins_enabled)
uint8_t i;

for (i = 0; i < 32; i++) {
if (pins_enabled & (1 << i)) {
if (pins_enabled & ((uint32_t)1 << i)) {
if (pins[i] != GPIO_UNDEF) {
if (i < UCG_PIN_COUNT) {
gpio_init(pins[i], GPIO_OUT);
Expand Down
10 changes: 5 additions & 5 deletions sys/cb_mux/cb_mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cb_mux_t *cb_mux_find_cbid(cb_mux_t *head, cb_mux_cbid_t cbid_val)

cb_mux_t *cb_mux_find_low(cb_mux_t *head)
{
cb_mux_t *entry;
cb_mux_t *entry = NULL;
cb_mux_t *entry_low = NULL;
cb_mux_cbid_t id = (cb_mux_cbid_t)(-1);

Expand All @@ -60,7 +60,7 @@ cb_mux_t *cb_mux_find_low(cb_mux_t *head)

cb_mux_t *cb_mux_find_high(cb_mux_t *head)
{
cb_mux_t *entry;
cb_mux_t *entry = NULL;
cb_mux_t *entry_high = NULL;
cb_mux_cbid_t id = 0;

Expand All @@ -81,7 +81,7 @@ cb_mux_cbid_t cb_mux_find_free_id(cb_mux_t *head)
{
uint32_t free;
cb_mux_cbid_t block;
cb_mux_t *entry;
cb_mux_t *entry = NULL;
uint8_t num;

/* Search for free IDs in blocks of 32 IDs */
Expand All @@ -105,7 +105,7 @@ cb_mux_cbid_t cb_mux_find_free_id(cb_mux_t *head)

/* Find which ID in block was free */
for (num = 0; num < 32; num++) {
if (~free & (1 << num)) {
if (~free & ((uint32_t)1 << num)) {
return block | num;
}
}
Expand All @@ -116,7 +116,7 @@ cb_mux_cbid_t cb_mux_find_free_id(cb_mux_t *head)

void cb_mux_iter(cb_mux_t *head, cb_mux_iter_t func, void *arg)
{
cb_mux_t *entry;
cb_mux_t *entry = NULL;

LL_FOREACH(head, entry) {
func(entry, arg);
Expand Down
4 changes: 4 additions & 0 deletions sys/include/net/gnrc/gomach/gomach.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ extern "C" {
#define GNRC_GOMACH_SUPERFRAME_DURATION_US (300LU * US_PER_MS)
#endif

#ifndef RTT_FREQUENCY
#error "RTT_FREQUENCY undefined."
#else
#if ((GNRC_GOMACH_SUPERFRAME_DURATION_US < ((1000LU *US_PER_MS) / RTT_FREQUENCY)) || \
(GNRC_GOMACH_SUPERFRAME_DURATION_US < (10 *GNRC_GOMACH_CP_DURATION_US)))
#undef GNRC_GOMACH_SUPERFRAME_DURATION_US
Expand All @@ -94,6 +97,7 @@ extern "C" {
#define GNRC_GOMACH_SUPERFRAME_DURATION_US (10 * GNRC_GOMACH_CP_DURATION_US)
#endif
#endif
#endif

/**
* @brief The maximum duration of the random period at the end of GoMacH's
Expand Down
26 changes: 13 additions & 13 deletions sys/net/network_layer/fib/fib.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ static int fib_sr_check_lifetime(fib_sr_t *fib_sr)
fib_sr->sr_lifetime = 0;

if (fib_sr->sr_path != NULL) {
fib_sr_entry_t *elt;
fib_sr_entry_t *elt = NULL;
LL_FOREACH(fib_sr->sr_path, elt) {
universal_address_rem(elt->address);
}
Expand Down Expand Up @@ -854,7 +854,7 @@ int fib_sr_delete(fib_table_t *table, fib_sr_t *fib_sr)
fib_sr->sr_lifetime = 0;

if (fib_sr->sr_path != NULL) {
fib_sr_entry_t *elt, *tmp;
fib_sr_entry_t *elt = NULL, *tmp = NULL;
LL_FOREACH_SAFE(fib_sr->sr_path, elt, tmp) {
universal_address_rem(elt->address);
elt->address = NULL;
Expand Down Expand Up @@ -920,7 +920,7 @@ int fib_sr_search(fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr, size_t ad
return -ENOENT;
}

fib_sr_entry_t *elt;
fib_sr_entry_t *elt = NULL;
LL_FOREACH(fib_sr->sr_path, elt) {
size_t addr_size_match = addr_size << 3;
if (universal_address_compare(elt->address, addr, &addr_size_match) == UNIVERSAL_ADDRESS_EQUAL) {
Expand Down Expand Up @@ -953,7 +953,7 @@ int fib_sr_entry_append(fib_table_t *table, fib_sr_t *fib_sr,
return -ENOENT;
}

fib_sr_entry_t *elt;
fib_sr_entry_t *elt = NULL;
LL_FOREACH(fib_sr->sr_path, elt) {
size_t addr_size_match = addr_size << 3;
if (universal_address_compare(elt->address, addr, &addr_size_match) == UNIVERSAL_ADDRESS_EQUAL) {
Expand Down Expand Up @@ -999,7 +999,7 @@ int fib_sr_entry_add(fib_table_t *table, fib_sr_t *fib_sr,
}

bool found = false;
fib_sr_entry_t *elt;
fib_sr_entry_t *elt = NULL;
LL_FOREACH(fib_sr->sr_path, elt) {
size_t addr_size_match = addr_size << 3;
if (universal_address_compare(elt->address, addr, &addr_size_match) == UNIVERSAL_ADDRESS_EQUAL) {
Expand All @@ -1023,7 +1023,7 @@ int fib_sr_entry_add(fib_table_t *table, fib_sr_t *fib_sr,
new_entry[0]->next = remaining;
}
else {
fib_sr_entry_t *elt, *tmp;
fib_sr_entry_t *elt = NULL, *tmp = NULL;
LL_FOREACH_SAFE(remaining, elt, tmp) {
universal_address_rem(elt->address);
elt->address = NULL;
Expand Down Expand Up @@ -1053,7 +1053,7 @@ int fib_sr_entry_delete(fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr, siz
return -ENOENT;
}

fib_sr_entry_t *elt, *tmp;
fib_sr_entry_t *elt = NULL, *tmp;
tmp = fib_sr->sr_path;
LL_FOREACH(fib_sr->sr_path, elt) {
size_t addr_size_match = addr_size << 3;
Expand All @@ -1064,7 +1064,7 @@ int fib_sr_entry_delete(fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr, siz
tmp->next = elt->next;
}
else {
fib_sr_entry_t *elt_del, *tmp_del;
fib_sr_entry_t *elt_del = NULL, *tmp_del = NULL;
LL_FOREACH_SAFE(tmp, elt_del, tmp_del) {
universal_address_rem(elt_del->address);
elt_del->address = NULL;
Expand Down Expand Up @@ -1104,7 +1104,7 @@ int fib_sr_entry_overwrite(fib_table_t *table, fib_sr_t *fib_sr,
return -ENOENT;
}

fib_sr_entry_t *elt, *elt_repl;
fib_sr_entry_t *elt = NULL, *elt_repl;
elt_repl = NULL;
LL_FOREACH(fib_sr->sr_path, elt) {
size_t addr_old_size_match = addr_old_size << 3;
Expand Down Expand Up @@ -1153,7 +1153,7 @@ int fib_sr_entry_get_address(fib_table_t *table, fib_sr_t *fib_sr, fib_sr_entry_
return -ENOENT;
}

fib_sr_entry_t *elt;
fib_sr_entry_t *elt = NULL;
LL_FOREACH(fib_sr->sr_path, elt) {
if (elt == sr_entry) {
if (universal_address_get_address(elt->address, addr, addr_size) != NULL) {
Expand Down Expand Up @@ -1190,7 +1190,7 @@ fib_sr_t* hit = NULL;
for (size_t i = 0; i < table->size; ++i) {
if (table->data.source_routes->headers[i].sr_lifetime != 0) {

fib_sr_entry_t *elt;
fib_sr_entry_t *elt = NULL;
LL_FOREACH(table->data.source_routes->headers[i].sr_path, elt) {
size_t addr_size_match = dst_size << 3;
if (universal_address_compare(elt->address, dst, &addr_size_match) == UNIVERSAL_ADDRESS_EQUAL) {
Expand Down Expand Up @@ -1221,7 +1221,7 @@ fib_sr_t* hit = NULL;
new_sr->sr_path = NULL;

/* and the path until the searched destination */
fib_sr_entry_t *elt_iter, *elt_add = NULL;
fib_sr_entry_t *elt_iter = NULL, *elt_add = NULL;

LL_FOREACH(table->data.source_routes->headers[i].sr_path, elt_iter) {
fib_sr_entry_t *new_entry;
Expand Down Expand Up @@ -1365,7 +1365,7 @@ int fib_sr_get_route(fib_table_t *table, uint8_t *dst, size_t dst_size, kernel_p
hit->sr_lifetime = 0;

if (hit->sr_path != NULL) {
fib_sr_entry_t *elt, *tmp;
fib_sr_entry_t *elt = NULL, *tmp = NULL;
LL_FOREACH_SAFE(hit->sr_path, elt, tmp) {
universal_address_rem(elt->address);
elt->address = NULL;
Expand Down
46 changes: 23 additions & 23 deletions sys/net/routing/nhdp/iib_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ iib_link_set_entry_t *iib_process_hello(kernel_pid_t if_pid, nib_entry_t *nb_elt
uint64_t validity_time, uint8_t is_sym_nb,
uint8_t is_lost)
{
iib_base_entry_t *base_elt;
iib_base_entry_t *base_elt = NULL;
iib_link_set_entry_t *ls_entry = NULL;
timex_t now;

Expand Down Expand Up @@ -138,9 +138,9 @@ iib_link_set_entry_t *iib_process_hello(kernel_pid_t if_pid, nib_entry_t *nb_elt

void iib_fill_wr_addresses(kernel_pid_t if_pid, struct rfc5444_writer *wr)
{
iib_base_entry_t *base_elt;
iib_link_set_entry_t *ls_elt;
nhdp_addr_entry_t *addr_elt;
iib_base_entry_t *base_elt = NULL;
iib_link_set_entry_t *ls_elt = NULL;
nhdp_addr_entry_t *addr_elt = NULL;
timex_t now;

mutex_lock(&mtx_iib_access);
Expand Down Expand Up @@ -214,8 +214,8 @@ void iib_fill_wr_addresses(kernel_pid_t if_pid, struct rfc5444_writer *wr)

void iib_update_lt_status(timex_t *now)
{
iib_base_entry_t *base_elt;
iib_link_set_entry_t *ls_elt, *ls_tmp;
iib_base_entry_t *base_elt = NULL;
iib_link_set_entry_t *ls_elt = NULL, *ls_tmp = NULL;

LL_FOREACH(iib_base_entry_head, base_elt) {
LL_FOREACH_SAFE(base_elt->link_set_head, ls_elt, ls_tmp) {
Expand All @@ -226,8 +226,8 @@ void iib_update_lt_status(timex_t *now)

void iib_propagate_nb_entry_change(nib_entry_t *old_entry, nib_entry_t *new_entry)
{
iib_base_entry_t *base_elt;
iib_link_set_entry_t *ls_elt;
iib_base_entry_t *base_elt = NULL;
iib_link_set_entry_t *ls_elt = NULL;
LL_FOREACH(iib_base_entry_head, base_elt) {
LL_FOREACH(base_elt->link_set_head, ls_elt) {
if (ls_elt->nb_elt == old_entry) {
Expand Down Expand Up @@ -314,7 +314,7 @@ void iib_process_metric_pckt(iib_link_set_entry_t *ls_entry, uint32_t metric_out
}
else if (ls_entry->metric_out == ls_entry->nb_elt->metric_out){
/* The corresponding neighbor tuples metric needs to be updated */
iib_base_entry_t *base_elt;
iib_base_entry_t *base_elt = NULL;
iib_link_set_entry_t *ls_elt;
ls_entry->nb_elt->metric_out = metric_out;
LL_FOREACH(iib_base_entry_head, base_elt) {
Expand Down Expand Up @@ -364,15 +364,15 @@ void iib_process_metric_refresh(void)
*/
static void cleanup_link_sets(void)
{
iib_base_entry_t *base_elt;
iib_base_entry_t *base_elt = NULL;

/* Loop through all link sets */
LL_FOREACH(iib_base_entry_head, base_elt) {
/* Loop through all link tuples of the link set */
iib_link_set_entry_t *ls_elt, *ls_tmp;
iib_link_set_entry_t *ls_elt = NULL, *ls_tmp = NULL;
LL_FOREACH_SAFE(base_elt->link_set_head, ls_elt, ls_tmp) {
/* Loop through all addresses of the link tuples */
nhdp_addr_entry_t *lt_elt, *lt_tmp;
nhdp_addr_entry_t *lt_elt = NULL, *lt_tmp = NULL;
LL_FOREACH_SAFE(ls_elt->address_list_head, lt_elt, lt_tmp) {
if (NHDP_ADDR_TMP_IN_REM_LIST(lt_elt->address)) {
/* Remove link tuple address if included in the Removed Addr List */
Expand All @@ -385,7 +385,7 @@ static void cleanup_link_sets(void)
if (!ls_elt->address_list_head) {
if (ls_elt->last_status == IIB_LT_STATUS_SYM) {
/* Remove all two hop entries for the corresponding link tuple */
iib_two_hop_set_entry_t *th_elt, *th_tmp;
iib_two_hop_set_entry_t *th_elt = NULL, *th_tmp = NULL;
LL_FOREACH_SAFE(base_elt->two_hop_set_head, th_elt, th_tmp) {
if (th_elt->ls_elt == ls_elt) {
rem_two_hop_entry(base_elt, th_elt);
Expand All @@ -406,9 +406,9 @@ static iib_link_set_entry_t *update_link_set(iib_base_entry_t *base_entry, nib_e
timex_t *now, uint64_t val_time,
uint8_t sym, uint8_t lost)
{
iib_link_set_entry_t *ls_elt, *ls_tmp;
iib_link_set_entry_t *ls_elt = NULL, *ls_tmp = NULL;
iib_link_set_entry_t *matching_lt = NULL;
nhdp_addr_entry_t *lt_elt;
nhdp_addr_entry_t *lt_elt = NULL;
timex_t v_time, l_hold;
uint8_t matches = 0;

Expand Down Expand Up @@ -643,8 +643,8 @@ static int update_two_hop_set(iib_base_entry_t *base_entry, iib_link_set_entry_t

/* If the link to the neighbor is still symmetric */
if (get_tuple_status(ls_entry, now) == IIB_LT_STATUS_SYM) {
iib_two_hop_set_entry_t *ths_elt, *ths_tmp;
nhdp_addr_t *addr_elt;
iib_two_hop_set_entry_t *ths_elt = NULL, *ths_tmp = NULL;
nhdp_addr_t *addr_elt = NULL;

/* Loop through all the two hop tuples of the two hop set */
LL_FOREACH_SAFE(base_entry->two_hop_set_head, ths_elt, ths_tmp) {
Expand Down Expand Up @@ -728,7 +728,7 @@ static void rem_two_hop_entry(iib_base_entry_t *base_entry, iib_two_hop_set_entr
static void update_nb_tuple_symmetry(iib_base_entry_t *base_entry,
iib_link_set_entry_t *ls_entry, timex_t *now)
{
iib_two_hop_set_entry_t *th_elt, *th_tmp;
iib_two_hop_set_entry_t *th_elt = NULL, *th_tmp = NULL;

/* First remove all two hop entries for the corresponding link tuple */
LL_FOREACH_SAFE(base_entry->two_hop_set_head, th_elt, th_tmp) {
Expand All @@ -739,9 +739,9 @@ static void update_nb_tuple_symmetry(iib_base_entry_t *base_entry,

/* Afterwards check the neighbor tuple containing the link tuple's addresses */
if ((ls_entry->nb_elt != NULL) && (ls_entry->nb_elt->symmetric == 1)) {
iib_base_entry_t *base_tmp;
iib_base_entry_t *base_tmp = NULL;
LL_FOREACH(iib_base_entry_head, base_tmp) {
iib_link_set_entry_t *ls_tmp;
iib_link_set_entry_t *ls_tmp = NULL;
LL_FOREACH(base_tmp->link_set_head, ls_tmp) {
if ((ls_entry->nb_elt == ls_tmp->nb_elt) && (ls_entry != ls_tmp)) {
if (timex_cmp(ls_tmp->sym_time, *now) == 1) {
Expand All @@ -764,9 +764,9 @@ static void rem_not_heard_nb_tuple(iib_link_set_entry_t *ls_entry, timex_t *now)
{
/* Check whether the corresponding neighbor tuple still exists */
if (ls_entry->nb_elt) {
iib_base_entry_t *base_tmp;
iib_base_entry_t *base_tmp = NULL;
LL_FOREACH(iib_base_entry_head, base_tmp) {
iib_link_set_entry_t *ls_tmp;
iib_link_set_entry_t *ls_tmp = NULL;
LL_FOREACH(base_tmp->link_set_head, ls_tmp) {
if ((ls_entry->nb_elt == ls_tmp->nb_elt) && (ls_entry != ls_tmp)) {
if (timex_cmp(ls_tmp->heard_time, *now) == 1) {
Expand Down Expand Up @@ -855,7 +855,7 @@ static void queue_rem(uint8_t *queue)
*/
static void dat_metric_refresh(void)
{
iib_base_entry_t *base_elt;
iib_base_entry_t *base_elt = NULL;
iib_link_set_entry_t *ls_elt;
uint32_t metric_temp;
double sum_total, sum_rcvd, loss;
Expand Down
Loading