From: Michel Pollet Date: Wed, 20 Jun 2018 08:13:16 +0000 (+0100) Subject: misc: Fix static analyzer warnings X-Git-Tag: v1.7~43 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=b8fb9e5be06275d2bb8d43d8b7b92c795678be58;p=sx%2Fsimavr.git misc: Fix static analyzer warnings Mostly intenting. Signed-off-by: Michel Pollet --- diff --git a/examples/board_hd44780/charlcd.c b/examples/board_hd44780/charlcd.c index 24f70f9..100cd34 100644 --- a/examples/board_hd44780/charlcd.c +++ b/examples/board_hd44780/charlcd.c @@ -100,7 +100,7 @@ void displayCB(void) /* function called whenever redisplay needed */ colors[color][2], /* text */ colors[color][3] /* shadow */ ); glPopMatrix(); - glutSwapBuffers(); + glutSwapBuffers(); } // gl timer. if the lcd is dirty, refresh display @@ -164,7 +164,7 @@ main( avr_load_firmware(avr, &f); ac_input_init(avr, &ac_input); avr_connect_irq(ac_input.irq + IRQ_AC_OUT, avr_io_getirq(avr, - AVR_IOCTL_IOPORT_GETIRQ('D'), 2)); + AVR_IOCTL_IOPORT_GETIRQ('D'), 2)); hd44780_init(avr, &hd44780, 20, 4); diff --git a/examples/parts/uart_pty.c b/examples/parts/uart_pty.c index 4f4edd0..632dbdc 100644 --- a/examples/parts/uart_pty.c +++ b/examples/parts/uart_pty.c @@ -209,8 +209,10 @@ uart_pty_thread( // write them in fifo uint8_t * dst = buffer; while (!uart_pty_fifo_isempty(&p->port[ti].in) && - dst < (buffer + sizeof(buffer))) - *dst++ = uart_pty_fifo_read(&p->port[ti].in); + (dst - buffer) < sizeof(buffer)) { + *dst = uart_pty_fifo_read(&p->port[ti].in); + dst++; + } size_t len = dst - buffer; TRACE(size_t r =) write(p->port[ti].s, buffer, len); TRACE(if (!p->port[ti].tap) hdump("pty send", buffer, r);) diff --git a/examples/parts/uart_pty.h b/examples/parts/uart_pty.h index c6e0603..a75f9f5 100644 --- a/examples/parts/uart_pty.h +++ b/examples/parts/uart_pty.h @@ -36,7 +36,7 @@ enum { DECLARE_FIFO(uint8_t,uart_pty_fifo, 512); typedef struct uart_pty_port_t { - int tap : 1, crlf : 1; + unsigned int tap : 1, crlf : 1; int s; // socket we chat on char slavename[64]; uart_pty_fifo_t in; diff --git a/simavr/sim/avr_timer.c b/simavr/sim/avr_timer.c index c05c7eb..3fcfd8b 100644 --- a/simavr/sim/avr_timer.c +++ b/simavr/sim/avr_timer.c @@ -41,8 +41,8 @@ _timer_get_ocr( int compi) { return p->io.avr->data[p->comp[compi].r_ocr] | - (p->comp[compi].r_ocrh ? - (p->io.avr->data[p->comp[compi].r_ocrh] << 8) : 0); + (p->comp[compi].r_ocrh ? + (p->io.avr->data[p->comp[compi].r_ocrh] << 8) : 0); } static uint16_t @@ -720,7 +720,7 @@ avr_timer_write_pending( cp[compi] = avr_regbit_get(avr, p->comp[compi].interrupt.raised); // write the value - // avr_core_watch_write(avr, addr, v); // This raises flags instead of clearing it. + // avr_core_watch_write(avr, addr, v); // This raises flags instead of clearing it. // clear any interrupts & flags avr_clear_interrupt_if(avr, &p->overflow, ov); diff --git a/simavr/sim/avr_twi.c b/simavr/sim/avr_twi.c index 8249ee7..5e351e5 100644 --- a/simavr/sim/avr_twi.c +++ b/simavr/sim/avr_twi.c @@ -170,7 +170,8 @@ avr_twi_write( uint8_t cleared = avr_regbit_get(avr, p->twi.raised); - /*int cleared = */avr_clear_interrupt_if(avr, &p->twi, twint); + /*int cleared = */ + avr_clear_interrupt_if(avr, &p->twi, twint); // AVR_TRACE(avr, "cleared %d\n", cleared); if (!twsto && avr_regbit_get(avr, p->twsto)) { diff --git a/simavr/sim/avr_usb.c b/simavr/sim/avr_usb.c index d87aca5..4acbcfd 100644 --- a/simavr/sim/avr_usb.c +++ b/simavr/sim/avr_usb.c @@ -372,7 +372,8 @@ ep_fifo_usb_write( if (len > ep_fifo_size(epstate)) { printf("EP OVERFI\n"); len = sizeof epstate->bank[epstate->current_bank].bytes; - }memcpy(epstate->bank[epstate->current_bank].bytes, buf, len); + } + memcpy(epstate->bank[epstate->current_bank].bytes, buf, len); epstate->bank[epstate->current_bank].tail = len; return 0; diff --git a/simavr/sim/sim_elf.c b/simavr/sim/sim_elf.c index f2f1a15..4c28959 100644 --- a/simavr/sim/sim_elf.c +++ b/simavr/sim/sim_elf.c @@ -434,10 +434,10 @@ elf_read_firmware( if (data_fuse) { if (elf_copy_section(".fuse", data_fuse, &firmware->fuse)) return -1; - firmware->fusesize = data_fuse->d_size; + firmware->fusesize = data_fuse->d_size; } if (data_lockbits) { - if (elf_copy_section(".lock", data_fuse, &firmware->lockbits)) + if (elf_copy_section(".lock", data_lockbits, &firmware->lockbits)) return -1; } // hdump("flash", avr->flash, offset); diff --git a/simavr/sim/sim_gdb.c b/simavr/sim/sim_gdb.c index c706b2a..de89b1c 100644 --- a/simavr/sim/sim_gdb.c +++ b/simavr/sim/sim_gdb.c @@ -320,7 +320,7 @@ gdb_handle_command( gdb_send_reply(g, rep); break; - } + } gdb_send_reply(g, ""); break; case '?': @@ -504,8 +504,8 @@ gdb_network_handler( sleep(5); return 1; } - int i = 1; - setsockopt (g->s, IPPROTO_TCP, TCP_NODELAY, &i, sizeof (i)); + int i = 1; + setsockopt (g->s, IPPROTO_TCP, TCP_NODELAY, &i, sizeof (i)); g->avr->state = cpu_Stopped; printf("%s connection opened\n", __FUNCTION__); } diff --git a/simavr/sim/sim_interrupts.c b/simavr/sim/sim_interrupts.c index b689a94..2791544 100644 --- a/simavr/sim/sim_interrupts.c +++ b/simavr/sim/sim_interrupts.c @@ -271,7 +271,7 @@ avr_service_interrupts( vector->pending = 0; avr->interrupt_state = avr_has_pending_interrupts(avr); } else { - if (vector && vector->trace) + if (vector->trace) printf("IRQ%d calling\n", vector->vector); _avr_push_addr(avr, avr->pc); avr_sreg_set(avr, S_I, 0); diff --git a/simavr/sim/sim_network.h b/simavr/sim/sim_network.h index a43e1d8..b3e0fb3 100644 --- a/simavr/sim/sim_network.h +++ b/simavr/sim/sim_network.h @@ -42,7 +42,7 @@ extern "C" { (ssize_t)recv( (sockfd), (char *)(buf), (len), (flags)) #define sleep(x) Sleep((x)*1000) -static inline int network_init() +static inline int network_init(void) { // Windows requires WinSock to be init before use WSADATA wsaData; @@ -52,7 +52,7 @@ static inline int network_init() return 0; } -static inline void network_release() +static inline void network_release(void) { // close WinSock WSACleanup(); @@ -69,13 +69,13 @@ static inline void network_release() #include #include -static inline int network_init() +static inline int network_init(void) { // nothing to do return 0; } -static inline void network_release() +static inline void network_release(void) { // nothing to do } diff --git a/simavr/sim/sim_vcd_file.c b/simavr/sim/sim_vcd_file.c index 9320a9f..c0d2767 100644 --- a/simavr/sim/sim_vcd_file.c +++ b/simavr/sim/sim_vcd_file.c @@ -265,13 +265,14 @@ avr_vcd_init_input( if (!strcmp(keyword, "$timescale")) { double cnt = 0; - vcd->vcd_to_us = 1; char *si = v->argv[1]; + + vcd->vcd_to_us = 1; while (si && *si && isdigit(*si)) cnt = (cnt * 10) + (*si++ - '0'); - while (*si == ' ') + while (si && *si == ' ') si++; - if (!*si) + if (si && !*si) si = v->argv[2]; // if (!strcmp(si, "ns")) // TODO: Check that, // vcd->vcd_to_us = cnt;