From f28eff61aeb62c867249c8cb21162dbd3c60cc37 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 25 Nov 2014 13:46:14 -0600 Subject: More fixes to problems noted by cppcheck. Some are kind of risky; some are real bugs. --- nuttx/drivers/wireless/cc3000/cc3000.c | 2 +- nuttx/fs/aio/aio_read.c | 2 +- nuttx/fs/aio/aio_write.c | 4 +++- nuttx/fs/fat/fs_configfat.c | 2 +- nuttx/fs/nxffs/nxffs_dump.c | 2 ++ nuttx/fs/nxffs/nxffs_initialize.c | 2 +- nuttx/fs/smartfs/smartfs_procfs.c | 10 ++++++++-- nuttx/fs/smartfs/smartfs_smart.c | 24 ++++++++++++------------ nuttx/libc/net/lib_inetpton.c | 4 ++-- nuttx/libc/stdio/lib_lowinstream.c | 2 +- nuttx/libc/stdlib/lib_mkstemp.c | 4 +--- nuttx/libc/stdlib/lib_qsort.c | 2 ++ nuttx/mm/mm_heap/mm_malloc.c | 2 +- nuttx/mm/mm_heap/mm_realloc.c | 4 ++-- 14 files changed, 38 insertions(+), 28 deletions(-) diff --git a/nuttx/drivers/wireless/cc3000/cc3000.c b/nuttx/drivers/wireless/cc3000/cc3000.c index 2c113b4f2..63b5d98cc 100644 --- a/nuttx/drivers/wireless/cc3000/cc3000.c +++ b/nuttx/drivers/wireless/cc3000/cc3000.c @@ -687,7 +687,7 @@ static void * cc3000_worker(FAR void *arg) * Will it fit? */ - if (data_to_recv >= priv->rx_buffer_max_len + if (data_to_recv >= priv->rx_buffer_max_len) { lowsyslog(LOG_INFO, "data_to_recv %d", data_to_recv); } diff --git a/nuttx/fs/aio/aio_read.c b/nuttx/fs/aio/aio_read.c index 104895436..fd05edbc6 100644 --- a/nuttx/fs/aio/aio_read.c +++ b/nuttx/fs/aio/aio_read.c @@ -96,7 +96,7 @@ static void aio_read_worker(FAR void *arg) #ifdef CONFIG_PRIORITY_INHERITANCE uint8_t prio; #endif - ssize_t nread; + ssize_t nread = 0; /* Get the information from the container, decant the AIO control block, * and free the container before starting any I/O. That will minimize diff --git a/nuttx/fs/aio/aio_write.c b/nuttx/fs/aio/aio_write.c index f05e357c3..6b8903895 100644 --- a/nuttx/fs/aio/aio_write.c +++ b/nuttx/fs/aio/aio_write.c @@ -113,8 +113,10 @@ static void aio_write_worker(FAR void *arg) #ifdef CONFIG_PRIORITY_INHERITANCE uint8_t prio; #endif - ssize_t nwritten; + ssize_t nwritten = 0; +#ifdef AIO_HAVE_FILEP int oflags; +#endif /* Get the information from the container, decant the AIO control block, * and free the container before starting any I/O. That will minimize diff --git a/nuttx/fs/fat/fs_configfat.c b/nuttx/fs/fat/fs_configfat.c index 5aff493c9..59e174ef5 100644 --- a/nuttx/fs/fat/fs_configfat.c +++ b/nuttx/fs/fat/fs_configfat.c @@ -950,7 +950,7 @@ int mkfatfs_configfatfs(FAR struct fat_format_s *fmt, { /* There must be reserved sectors in order to have a backup boot sector */ - if (fmt->ff_rsvdseccount > 0 && fmt->ff_rsvdseccount >= 2) + if (fmt->ff_rsvdseccount >= 2) { /* Sector 0 is the MBR; 1... ff_rsvdseccount are reserved. Try the next * the last reserved sector. diff --git a/nuttx/fs/nxffs/nxffs_dump.c b/nuttx/fs/nxffs/nxffs_dump.c index 181aaaebe..19e4d4b5c 100644 --- a/nuttx/fs/nxffs/nxffs_dump.c +++ b/nuttx/fs/nxffs/nxffs_dump.c @@ -67,7 +67,9 @@ struct nxffs_blkinfo_s off_t nblocks; off_t block; off_t offset; +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_FS) bool verbose; +#endif }; /**************************************************************************** diff --git a/nuttx/fs/nxffs/nxffs_initialize.c b/nuttx/fs/nxffs/nxffs_initialize.c index 3fb9e2b77..d7d55f077 100644 --- a/nuttx/fs/nxffs/nxffs_initialize.c +++ b/nuttx/fs/nxffs/nxffs_initialize.c @@ -410,7 +410,7 @@ int nxffs_limits(FAR struct nxffs_volume_s *volume) if (!noinodes) { - while ((ret = nxffs_nextentry(volume, offset, &entry)) == OK) + while (nxffs_nextentry(volume, offset, &entry) == OK) { /* Discard the entry and guess the next offset. */ diff --git a/nuttx/fs/smartfs/smartfs_procfs.c b/nuttx/fs/smartfs/smartfs_procfs.c index 2b56f366d..e74d65944 100644 --- a/nuttx/fs/smartfs/smartfs_procfs.c +++ b/nuttx/fs/smartfs/smartfs_procfs.c @@ -709,7 +709,9 @@ static size_t smartfs_status_read(FAR struct file *filep, FAR char *buffer, FAR struct smartfs_file_s *priv; int ret; size_t len; +#if 0 /* Not used */ int utilization; +#endif priv = (FAR struct smartfs_file_s *) filep->f_priv; @@ -729,6 +731,7 @@ static size_t smartfs_status_read(FAR struct file *filep, FAR char *buffer, if (ret == OK) { +#if 0 /* Not used */ /* Calculate the sector utilization percentage */ if (procfs_data.blockerases == 0) @@ -741,6 +744,7 @@ static size_t smartfs_status_read(FAR struct file *filep, FAR char *buffer, procfs_data.unusedsectors) / (procfs_data.blockerases * procfs_data.sectorsperblk); } +#endif /* Format and return data in the buffer */ @@ -756,8 +760,10 @@ static size_t smartfs_status_read(FAR struct file *filep, FAR char *buffer, procfs_data.formatsector, procfs_data.dirsector, procfs_data.freesectors, procfs_data.releasesectors, procfs_data.sectorsperblk); - //procfs_data.unusedsectors, procfs_data.blockerases, - //procfs_data.sectorsperblk, utilization); +#if 0 /* Not used */ + procfs_data.unusedsectors, procfs_data.blockerases, + procfs_data.sectorsperblk, utilization); +#endif } /* Indicate we have already provided all the data */ diff --git a/nuttx/fs/smartfs/smartfs_smart.c b/nuttx/fs/smartfs/smartfs_smart.c index bcbda7de8..0b9a373b1 100644 --- a/nuttx/fs/smartfs/smartfs_smart.c +++ b/nuttx/fs/smartfs/smartfs_smart.c @@ -1441,7 +1441,7 @@ static int smartfs_unbind(void *handle, FAR struct inode **blkdriver) static int smartfs_statfs(struct inode *mountpt, struct statfs *buf) { struct smartfs_mountpt_s *fs; - int ret = OK; + int ret; /* Sanity checks */ @@ -1483,11 +1483,11 @@ static int smartfs_statfs(struct inode *mountpt, struct statfs *buf) static int smartfs_unlink(struct inode *mountpt, const char *relpath) { - struct smartfs_mountpt_s *fs; - int ret = OK; - struct smartfs_entry_s entry; - const char *filename; - uint16_t parentdirsector; + struct smartfs_mountpt_s *fs; + int ret; + struct smartfs_entry_s entry; + const char *filename; + uint16_t parentdirsector; /* Sanity checks */ @@ -1627,11 +1627,11 @@ errout_with_semaphore: int smartfs_rmdir(struct inode *mountpt, const char *relpath) { - struct smartfs_mountpt_s *fs; - int ret = OK; - struct smartfs_entry_s entry; - const char *filename; - uint16_t parentdirsector; + struct smartfs_mountpt_s *fs; + int ret; + struct smartfs_entry_s entry; + const char *filename; + uint16_t parentdirsector; /* Sanity checks */ @@ -1916,7 +1916,7 @@ static int smartfs_stat(struct inode *mountpt, const char *relpath, struct stat { struct smartfs_mountpt_s *fs; struct smartfs_entry_s entry; - int ret = -ENOENT; + int ret; uint16_t parentdirsector; const char *filename; diff --git a/nuttx/libc/net/lib_inetpton.c b/nuttx/libc/net/lib_inetpton.c index 2805a7047..8b058e044 100644 --- a/nuttx/libc/net/lib_inetpton.c +++ b/nuttx/libc/net/lib_inetpton.c @@ -147,7 +147,7 @@ int inet_pton(int af, FAR const char *src, FAR void *dst) break; } - if (numoffset <= 0) + if (numoffset < 1) { /* Empty numeric string */ @@ -245,7 +245,7 @@ int inet_pton(int af, FAR const char *src, FAR void *dst) break; } - if (ch != '\0' && numoffset <= 0) + if (ch != '\0' && numoffset < 1) { /* Empty numeric string */ diff --git a/nuttx/libc/stdio/lib_lowinstream.c b/nuttx/libc/stdio/lib_lowinstream.c index 7284601e8..8c11fee90 100644 --- a/nuttx/libc/stdio/lib_lowinstream.c +++ b/nuttx/libc/stdio/lib_lowinstream.c @@ -65,7 +65,7 @@ static int lowinstream_getc(FAR struct lib_instream_s *this) /* Get the next character from the incoming stream */ - ret = up_getc(ch) + ret = up_getc(ch); if (ret != EOF) { this->nget++; diff --git a/nuttx/libc/stdlib/lib_mkstemp.c b/nuttx/libc/stdlib/lib_mkstemp.c index 729dfa535..94b6dcc0a 100644 --- a/nuttx/libc/stdlib/lib_mkstemp.c +++ b/nuttx/libc/stdlib/lib_mkstemp.c @@ -149,9 +149,7 @@ static void incr_base62(void) static void get_base62(FAR uint8_t *ptr) { - int ret; - - while ((ret = sem_wait(&g_b62sem)) < 0) + while (sem_wait(&g_b62sem) < 0) { DEBUGASSERT(errno == EINTR); } diff --git a/nuttx/libc/stdlib/lib_qsort.c b/nuttx/libc/stdlib/lib_qsort.c index 0579b1510..0ce30e999 100644 --- a/nuttx/libc/stdlib/lib_qsort.c +++ b/nuttx/libc/stdlib/lib_qsort.c @@ -213,6 +213,7 @@ loop: swap(pl, pl - size); } } + return; } @@ -230,6 +231,7 @@ loop: if ((r = pd - pc) > size) { /* Iterate rather than recurse to save stack space */ + base = pn - r; nmemb = r / size; goto loop; diff --git a/nuttx/mm/mm_heap/mm_malloc.c b/nuttx/mm/mm_heap/mm_malloc.c index 20b1916c8..9890e5712 100644 --- a/nuttx/mm/mm_heap/mm_malloc.c +++ b/nuttx/mm/mm_heap/mm_malloc.c @@ -91,7 +91,7 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size) /* Handle bad sizes */ - if (size <= 0) + if (size < 1) { return NULL; } diff --git a/nuttx/mm/mm_heap/mm_realloc.c b/nuttx/mm/mm_heap/mm_realloc.c index f41d019b5..5778975f5 100644 --- a/nuttx/mm/mm_heap/mm_realloc.c +++ b/nuttx/mm/mm_heap/mm_realloc.c @@ -101,7 +101,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, /* If size is zero, then realloc is equivalent to free */ - if (size <= 0) + if (size < 1) { mm_free(heap, oldmem); return NULL; @@ -170,7 +170,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, * previous chunk is smaller than the next chunk. */ - if (prevsize > 0 && (nextsize >= prevsize || nextsize <= 0)) + if (prevsize > 0 && (nextsize >= prevsize || nextsize < 1)) { /* Can we get everything we need from the previous chunk? */ -- cgit v1.2.3