From b756c4b51f51427339bf3649430f8470f64d7a8d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 25 Nov 2014 10:32:54 -0600 Subject: Fixes for more complaints from cppcheck --- apps/examples/bridge/host_main.c | 5 ----- apps/examples/buttons/buttons_main.c | 6 +++-- apps/examples/cc3000/telnetd_daemon.c | 2 +- apps/examples/elf/tests/mutex/mutex.c | 33 ++++++++++++++------------- apps/examples/ftpc/ftpc_cmds.c | 2 +- apps/examples/mm/mm_main.c | 38 ++++++++++++++++++-------------- apps/examples/nxffs/nxffs_main.c | 27 ++++++++++++----------- apps/examples/nxflat/tests/mutex/mutex.c | 33 ++++++++++++++------------- apps/examples/nximage/nximage_main.c | 2 +- apps/examples/nxtext/nxtext_popup.c | 2 ++ 10 files changed, 77 insertions(+), 73 deletions(-) diff --git a/apps/examples/bridge/host_main.c b/apps/examples/bridge/host_main.c index 0a8c3f970..0a2cdc311 100644 --- a/apps/examples/bridge/host_main.c +++ b/apps/examples/bridge/host_main.c @@ -219,11 +219,6 @@ int main(int argc, char *argv[]) goto errout_with_recvsd; } - if (nrecvd != nrecvd) - { - fprintf(stderr, LABEL "ERROR: Number of bytes received differs from number sent\n"); - } - /* Dump the received packet */ for (i = 0, j = 0; i < nrecvd; i++) diff --git a/apps/examples/buttons/buttons_main.c b/apps/examples/buttons/buttons_main.c index a76c173a2..e971d1c30 100644 --- a/apps/examples/buttons/buttons_main.c +++ b/apps/examples/buttons/buttons_main.c @@ -404,7 +404,9 @@ int buttons_main(int argc, char *argv[]) { uint8_t newset; irqstate_t flags; +#ifdef CONFIG_ARCH_IRQBUTTONS int i; +#endif /* If this example is configured as an NX add-on, then limit the number of * samples that we collect before returning. Otherwise, we never return @@ -425,7 +427,7 @@ int buttons_main(int argc, char *argv[]) board_button_initialize(); - /* Register to recieve button interrupts */ + /* Register to receive button interrupts */ #ifdef CONFIG_ARCH_IRQBUTTONS for (i = CONFIG_EXAMPLES_IRQBUTTONS_MIN; i <= CONFIG_EXAMPLES_IRQBUTTONS_MAX; i++) @@ -496,7 +498,7 @@ int buttons_main(int argc, char *argv[]) /* Un-register button handlers */ -#if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_NSH_BUILTIN_APPS) +#ifdef CONFIG_ARCH_IRQBUTTONS for (i = CONFIG_EXAMPLES_IRQBUTTONS_MIN; i <= CONFIG_EXAMPLES_IRQBUTTONS_MAX; i++) { (void)board_button_irq(i, NULL); diff --git a/apps/examples/cc3000/telnetd_daemon.c b/apps/examples/cc3000/telnetd_daemon.c index 223774190..4045bb38c 100644 --- a/apps/examples/cc3000/telnetd_daemon.c +++ b/apps/examples/cc3000/telnetd_daemon.c @@ -201,7 +201,7 @@ static int telnetd_daemon(int argc, char *argv[]) nllvdbg("Creating the telnet driver\n"); devpath = telnetd_driver(acceptsd, daemon); - if (devpath < 0) + if (devpath == NULL) { nlldbg("telnetd_driver failed\n"); goto errout_with_acceptsd; diff --git a/apps/examples/elf/tests/mutex/mutex.c b/apps/examples/elf/tests/mutex/mutex.c index 2446e62eb..0d5ff1d2a 100644 --- a/apps/examples/elf/tests/mutex/mutex.c +++ b/apps/examples/elf/tests/mutex/mutex.c @@ -76,29 +76,29 @@ void thread_func(void *parameter) for (i = 0; i < 20 && !bendoftest; i++); { if ((pthread_mutex_lock(&mut)) != 0) - { - printf("ERROR thread %d: pthread_mutex_lock failed\n", my_id); - } + { + printf("ERROR thread %d: pthread_mutex_lock failed\n", my_id); + } if (my_mutex == 1) - { - printf("ERROR thread=%d: " - "my_mutex should be zero, instead my_mutex=%d\n", - my_id, my_mutex); - nerrors[my_ndx]++; - } + { + printf("ERROR thread=%d: " + "my_mutex should be zero, instead my_mutex=%d\n", + my_id, my_mutex); + nerrors[my_ndx]++; + } my_mutex = 1; usleep(100000); my_mutex = 0; - + if ((pthread_mutex_unlock(&mut)) != 0) - { - printf("ERROR thread %d: pthread_mutex_unlock failed\n", my_id); - } + { + printf("ERROR thread %d: pthread_mutex_unlock failed\n", my_id); + } nloops[my_ndx]++; - } + } } /**************************************************************************** @@ -141,9 +141,8 @@ int main(int argc, char **argv) pthread_join(thread2, NULL); printf("\tThread1\tThread2\n"); - printf("Loops\t%ld\t%ld\n", nloops[0], nloops[1]); - printf("Errors\t%ld\t%ld\n", nerrors[0], nerrors[1]); + printf("Loops\t%lu\t%lu\n", nloops[0], nloops[1]); + printf("Errors\t%lu\t%lu\n", nerrors[0], nerrors[1]); return 0; } - diff --git a/apps/examples/ftpc/ftpc_cmds.c b/apps/examples/ftpc/ftpc_cmds.c index d5dba926a..15e8ffd19 100644 --- a/apps/examples/ftpc/ftpc_cmds.c +++ b/apps/examples/ftpc/ftpc_cmds.c @@ -181,7 +181,7 @@ int cmd_rrename(SESSION handle, int argc, char **argv) int cmd_rsize(SESSION handle, int argc, char **argv) { off_t size = ftpc_filesize(handle, argv[1]); - printf("SIZE: %lu\n", size); + printf("SIZE: %lu\n", (unsigned long)size); return OK; } diff --git a/apps/examples/mm/mm_main.c b/apps/examples/mm/mm_main.c index ffb7774a6..40ddc7618 100644 --- a/apps/examples/mm/mm_main.c +++ b/apps/examples/mm/mm_main.c @@ -126,16 +126,16 @@ static void mm_showmallinfo(void) { alloc_info = mallinfo(); printf(" mallinfo:\n"); - printf(" Total space allocated from system = %ld\n", - alloc_info.arena); - printf(" Number of non-inuse chunks = %ld\n", - alloc_info.ordblks); - printf(" Largest non-inuse chunk = %ld\n", - alloc_info.mxordblk); - printf(" Total allocated space = %ld\n", - alloc_info.uordblks); - printf(" Total non-inuse space = %ld\n", - alloc_info.fordblks); + printf(" Total space allocated from system = %lu\n", + (unsigned long)alloc_info.arena); + printf(" Number of non-inuse chunks = %lu\n", + (unsigned long)alloc_info.ordblks); + printf(" Largest non-inuse chunk = %lu\n", + (unsigned long)alloc_info.mxordblk); + printf(" Total allocated space = %lu\n", + (unsigned long)alloc_info.uordblks); + printf(" Total non-inuse space = %lu\n", + (unsigned long)alloc_info.fordblks); } static void do_mallocs(void **mem, const int *size, const int *seq, int n) @@ -160,11 +160,13 @@ static void do_mallocs(void **mem, const int *size, const int *seq, int n) fprintf(stderr, "(%d)malloc failed for allocsize=%d\n", i, allocsize); if (allocsize > alloc_info.mxordblk) { - fprintf(stderr, " Normal, largest free block is only %ld\n", alloc_info.mxordblk); + fprintf(stderr, " Normal, largest free block is only %lu\n", + (unsigned long)alloc_info.mxordblk); } else { - fprintf(stderr, " ERROR largest free block is %ld\n", alloc_info.mxordblk); + fprintf(stderr, " ERROR largest free block is %lu\n", + (unsigned long)alloc_info.mxordblk); exit(1); } } @@ -199,11 +201,13 @@ static void do_reallocs(void **mem, const int *oldsize, const int *newsize, cons fprintf(stderr, "(%d)realloc failed for allocsize=%d\n", i, allocsize); if (allocsize > alloc_info.mxordblk) { - fprintf(stderr, " Normal, largest free block is only %ld\n", alloc_info.mxordblk); + fprintf(stderr, " Normal, largest free block is only %lu\n", + (unsigned long)alloc_info.mxordblk); } else { - fprintf(stderr, " ERROR largest free block is %ld\n", alloc_info.mxordblk); + fprintf(stderr, " ERROR largest free block is %lu\n", + (unsigned long)alloc_info.mxordblk); exit(1); } } @@ -237,11 +241,13 @@ static void do_memaligns(void **mem, const int *size, const int *align, const in fprintf(stderr, "(%d)memalign failed for allocsize=%d\n", i, allocsize); if (allocsize > alloc_info.mxordblk) { - fprintf(stderr, " Normal, largest free block is only %ld\n", alloc_info.mxordblk); + fprintf(stderr, " Normal, largest free block is only %lu\n", + (unsigned long)alloc_info.mxordblk); } else { - fprintf(stderr, " ERROR largest free block is %ld\n", alloc_info.mxordblk); + fprintf(stderr, " ERROR largest free block is %lu\n", + (unsigned long)alloc_info.mxordblk); exit(1); } } diff --git a/apps/examples/nxffs/nxffs_main.c b/apps/examples/nxffs/nxffs_main.c index 1aa563e17..1c369937f 100644 --- a/apps/examples/nxffs/nxffs_main.c +++ b/apps/examples/nxffs/nxffs_main.c @@ -329,7 +329,7 @@ static inline int nxffs_wrfile(FAR struct nxffs_filedesc_s *file) { printf("ERROR: Failed to open file for writing: %d\n", errno); printf(" File name: %s\n", file->name); - printf(" File size: %d\n", file->len); + printf(" File size: %lu\n", (unsigned long)file->len); } nxffs_freefile(file); return ERROR; @@ -361,7 +361,7 @@ static inline int nxffs_wrfile(FAR struct nxffs_filedesc_s *file) { printf("ERROR: Failed to write file: %d\n", err); printf(" File name: %s\n", file->name); - printf(" File size: %d\n", file->len); + printf(" File size: %lu\n", (unsigned long)file->len); printf(" Write offset: %ld\n", (long)offset); printf(" Write size: %ld\n", (long)nbytestowrite); ret = ERROR; @@ -390,7 +390,7 @@ static inline int nxffs_wrfile(FAR struct nxffs_filedesc_s *file) { printf("ERROR: Partial write:\n"); printf(" File name: %s\n", file->name); - printf(" File size: %d\n", file->len); + printf(" File size: %lu\n", (unsigned long)file->len); printf(" Write offset: %ld\n", (long)offset); printf(" Write size: %ld\n", (long)nbytestowrite); printf(" Written: %ld\n", (long)nbyteswritten); @@ -459,7 +459,7 @@ static ssize_t nxffs_rdblock(int fd, FAR struct nxffs_filedesc_s *file, { printf("ERROR: Failed to read file: %d\n", errno); printf(" File name: %s\n", file->name); - printf(" File size: %d\n", file->len); + printf(" File size: %lu\n", (unsigned long)file->len); printf(" Read offset: %ld\n", (long)offset); printf(" Read size: %ld\n", (long)len); return ERROR; @@ -479,7 +479,7 @@ static ssize_t nxffs_rdblock(int fd, FAR struct nxffs_filedesc_s *file, { printf("ERROR: Partial read:\n"); printf(" File name: %s\n", file->name); - printf(" File size: %d\n", file->len); + printf(" File size: %lu\n", (unsigned long)file->len); printf(" Read offset: %ld\n", (long)offset); printf(" Read size: %ld\n", (long)len); printf(" Bytes read: %ld\n", (long)nbytesread); @@ -507,7 +507,7 @@ static inline int nxffs_rdfile(FAR struct nxffs_filedesc_s *file) { printf("ERROR: Failed to open file for reading: %d\n", errno); printf(" File name: %s\n", file->name); - printf(" File size: %d\n", file->len); + printf(" File size: %lu\n", (unsigned long)file->len); } return ERROR; } @@ -531,9 +531,10 @@ static inline int nxffs_rdfile(FAR struct nxffs_filedesc_s *file) crc = crc32(g_fileimage, file->len); if (crc != file->crc) { - printf("ERROR: Bad CRC: %d vs %d\n", crc, file->crc); + printf("ERROR: Bad CRC: %u vs %u\n", + (unsigned int)crc, (unsigned int)file->crc); printf(" File name: %s\n", file->name); - printf(" File size: %d\n", file->len); + printf(" File size: %lu\n", (unsigned long)file->len); close(fd); return ERROR; } @@ -545,8 +546,8 @@ static inline int nxffs_rdfile(FAR struct nxffs_filedesc_s *file) { printf("ERROR: Read past the end of file\n"); printf(" File name: %s\n", file->name); - printf(" File size: %d\n", file->len); - printf(" Bytes read: %d\n", nbytesread); + printf(" File size: %lu\n", (unsigned long)file->len); + printf(" Bytes read: %ld\n", (long)nbytesread); close(fd); return ERROR; } @@ -588,7 +589,7 @@ static int nxffs_verifyfs(void) { printf("ERROR: Failed to read a file: %d\n", i); printf(" File name: %s\n", file->name); - printf(" File size: %d\n", file->len); + printf(" File size: %lu\n", (unsigned long)file->len); return ERROR; } } @@ -663,7 +664,7 @@ static int nxffs_delfiles(void) { printf("ERROR: Unlink %d failed: %d\n", i+1, errno); printf(" File name: %s\n", file->name); - printf(" File size: %d\n", file->len); + printf(" File size: %lu\n", (unsigned long)file->len); printf(" File index: %d\n", j); } else @@ -710,7 +711,7 @@ static int nxffs_delallfiles(void) { printf("ERROR: Unlink %d failed: %d\n", i+1, errno); printf(" File name: %s\n", file->name); - printf(" File size: %d\n", file->len); + printf(" File size: %lu\n", (unsigned long)file->len); printf(" File index: %d\n", i); } else diff --git a/apps/examples/nxflat/tests/mutex/mutex.c b/apps/examples/nxflat/tests/mutex/mutex.c index 9a2d5f120..c15b2512a 100644 --- a/apps/examples/nxflat/tests/mutex/mutex.c +++ b/apps/examples/nxflat/tests/mutex/mutex.c @@ -76,29 +76,29 @@ void thread_func(void *parameter) for (i = 0; i < 20 && !bendoftest; i++); { if ((pthread_mutex_lock(&mut)) != 0) - { - printf("ERROR thread %d: pthread_mutex_lock failed\n", my_id); - } + { + printf("ERROR thread %d: pthread_mutex_lock failed\n", my_id); + } if (my_mutex == 1) - { - printf("ERROR thread=%d: " - "my_mutex should be zero, instead my_mutex=%d\n", - my_id, my_mutex); - nerrors[my_ndx]++; - } + { + printf("ERROR thread=%d: " + "my_mutex should be zero, instead my_mutex=%d\n", + my_id, my_mutex); + nerrors[my_ndx]++; + } my_mutex = 1; usleep(100000); my_mutex = 0; - + if ((pthread_mutex_unlock(&mut)) != 0) - { - printf("ERROR thread %d: pthread_mutex_unlock failed\n", my_id); - } + { + printf("ERROR thread %d: pthread_mutex_unlock failed\n", my_id); + } nloops[my_ndx]++; - } + } } /**************************************************************************** @@ -141,9 +141,8 @@ int main(int argc, char **argv) pthread_join(thread2, NULL); printf("\tThread1\tThread2\n"); - printf("Loops\t%ld\t%ld\n", nloops[0], nloops[1]); - printf("Errors\t%ld\t%ld\n", nerrors[0], nerrors[1]); + printf("Loops\t%lu\t%lu\n", nloops[0], nloops[1]); + printf("Errors\t%lu\t%lu\n", nerrors[0], nerrors[1]); return 0; } - diff --git a/apps/examples/nximage/nximage_main.c b/apps/examples/nximage/nximage_main.c index 0c3340a46..4b3d75dce 100644 --- a/apps/examples/nximage/nximage_main.c +++ b/apps/examples/nximage/nximage_main.c @@ -237,7 +237,7 @@ int nximage_main(int argc, char *argv[]) /* Set the background to the configured background color */ color = nximage_bgcolor(); - printf("nximage_main: Set background color=%d\n", color); + printf("nximage_main: Set background color=%u\n", color); ret = nx_setbgcolor(g_nximage.hnx, &color); if (ret < 0) diff --git a/apps/examples/nxtext/nxtext_popup.c b/apps/examples/nxtext/nxtext_popup.c index 252ad3358..6d4719e19 100644 --- a/apps/examples/nxtext/nxtext_popup.c +++ b/apps/examples/nxtext/nxtext_popup.c @@ -180,7 +180,9 @@ static inline void nxpu_fillwindow(NXWINDOW hwnd, FAR struct nxtext_state_s *st) { int ret; +#ifdef CONFIG_NX_KBD int i; +#endif ret = nx_fill(hwnd, rect, st->wcolor); if (ret < 0) -- cgit v1.2.3