More fixes to problems noted by cppcheck. Some are kind of risky; some are real bugs.

This commit is contained in:
Gregory Nutt 2014-11-25 13:46:14 -06:00
parent 2994448d85
commit 9ac09db800
14 changed files with 38 additions and 28 deletions

View File

@ -687,7 +687,7 @@ static void * cc3000_worker(FAR void *arg)
* Will it fit? * 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); lowsyslog(LOG_INFO, "data_to_recv %d", data_to_recv);
} }

View File

@ -96,7 +96,7 @@ static void aio_read_worker(FAR void *arg)
#ifdef CONFIG_PRIORITY_INHERITANCE #ifdef CONFIG_PRIORITY_INHERITANCE
uint8_t prio; uint8_t prio;
#endif #endif
ssize_t nread; ssize_t nread = 0;
/* Get the information from the container, decant the AIO control block, /* Get the information from the container, decant the AIO control block,
* and free the container before starting any I/O. That will minimize * and free the container before starting any I/O. That will minimize

View File

@ -113,8 +113,10 @@ static void aio_write_worker(FAR void *arg)
#ifdef CONFIG_PRIORITY_INHERITANCE #ifdef CONFIG_PRIORITY_INHERITANCE
uint8_t prio; uint8_t prio;
#endif #endif
ssize_t nwritten; ssize_t nwritten = 0;
#ifdef AIO_HAVE_FILEP
int oflags; int oflags;
#endif
/* Get the information from the container, decant the AIO control block, /* Get the information from the container, decant the AIO control block,
* and free the container before starting any I/O. That will minimize * and free the container before starting any I/O. That will minimize

View File

@ -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 */ /* 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 /* Sector 0 is the MBR; 1... ff_rsvdseccount are reserved. Try the next
* the last reserved sector. * the last reserved sector.

View File

@ -67,7 +67,9 @@ struct nxffs_blkinfo_s
off_t nblocks; off_t nblocks;
off_t block; off_t block;
off_t offset; off_t offset;
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_FS)
bool verbose; bool verbose;
#endif
}; };
/**************************************************************************** /****************************************************************************

View File

@ -410,7 +410,7 @@ int nxffs_limits(FAR struct nxffs_volume_s *volume)
if (!noinodes) 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. */ /* Discard the entry and guess the next offset. */

View File

@ -709,7 +709,9 @@ static size_t smartfs_status_read(FAR struct file *filep, FAR char *buffer,
FAR struct smartfs_file_s *priv; FAR struct smartfs_file_s *priv;
int ret; int ret;
size_t len; size_t len;
#if 0 /* Not used */
int utilization; int utilization;
#endif
priv = (FAR struct smartfs_file_s *) filep->f_priv; 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 (ret == OK)
{ {
#if 0 /* Not used */
/* Calculate the sector utilization percentage */ /* Calculate the sector utilization percentage */
if (procfs_data.blockerases == 0) 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.unusedsectors) / (procfs_data.blockerases *
procfs_data.sectorsperblk); procfs_data.sectorsperblk);
} }
#endif
/* Format and return data in the buffer */ /* 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.formatsector, procfs_data.dirsector,
procfs_data.freesectors, procfs_data.releasesectors, procfs_data.freesectors, procfs_data.releasesectors,
procfs_data.sectorsperblk); procfs_data.sectorsperblk);
//procfs_data.unusedsectors, procfs_data.blockerases, #if 0 /* Not used */
//procfs_data.sectorsperblk, utilization); procfs_data.unusedsectors, procfs_data.blockerases,
procfs_data.sectorsperblk, utilization);
#endif
} }
/* Indicate we have already provided all the data */ /* Indicate we have already provided all the data */

View File

@ -1441,7 +1441,7 @@ static int smartfs_unbind(void *handle, FAR struct inode **blkdriver)
static int smartfs_statfs(struct inode *mountpt, struct statfs *buf) static int smartfs_statfs(struct inode *mountpt, struct statfs *buf)
{ {
struct smartfs_mountpt_s *fs; struct smartfs_mountpt_s *fs;
int ret = OK; int ret;
/* Sanity checks */ /* Sanity checks */
@ -1484,7 +1484,7 @@ static int smartfs_statfs(struct inode *mountpt, struct statfs *buf)
static int smartfs_unlink(struct inode *mountpt, const char *relpath) static int smartfs_unlink(struct inode *mountpt, const char *relpath)
{ {
struct smartfs_mountpt_s *fs; struct smartfs_mountpt_s *fs;
int ret = OK; int ret;
struct smartfs_entry_s entry; struct smartfs_entry_s entry;
const char *filename; const char *filename;
uint16_t parentdirsector; uint16_t parentdirsector;
@ -1628,7 +1628,7 @@ errout_with_semaphore:
int smartfs_rmdir(struct inode *mountpt, const char *relpath) int smartfs_rmdir(struct inode *mountpt, const char *relpath)
{ {
struct smartfs_mountpt_s *fs; struct smartfs_mountpt_s *fs;
int ret = OK; int ret;
struct smartfs_entry_s entry; struct smartfs_entry_s entry;
const char *filename; const char *filename;
uint16_t parentdirsector; uint16_t parentdirsector;
@ -1916,7 +1916,7 @@ static int smartfs_stat(struct inode *mountpt, const char *relpath, struct stat
{ {
struct smartfs_mountpt_s *fs; struct smartfs_mountpt_s *fs;
struct smartfs_entry_s entry; struct smartfs_entry_s entry;
int ret = -ENOENT; int ret;
uint16_t parentdirsector; uint16_t parentdirsector;
const char *filename; const char *filename;

View File

@ -147,7 +147,7 @@ int inet_pton(int af, FAR const char *src, FAR void *dst)
break; break;
} }
if (numoffset <= 0) if (numoffset < 1)
{ {
/* Empty numeric string */ /* Empty numeric string */
@ -245,7 +245,7 @@ int inet_pton(int af, FAR const char *src, FAR void *dst)
break; break;
} }
if (ch != '\0' && numoffset <= 0) if (ch != '\0' && numoffset < 1)
{ {
/* Empty numeric string */ /* Empty numeric string */

View File

@ -65,7 +65,7 @@ static int lowinstream_getc(FAR struct lib_instream_s *this)
/* Get the next character from the incoming stream */ /* Get the next character from the incoming stream */
ret = up_getc(ch) ret = up_getc(ch);
if (ret != EOF) if (ret != EOF)
{ {
this->nget++; this->nget++;

View File

@ -149,9 +149,7 @@ static void incr_base62(void)
static void get_base62(FAR uint8_t *ptr) static void get_base62(FAR uint8_t *ptr)
{ {
int ret; while (sem_wait(&g_b62sem) < 0)
while ((ret = sem_wait(&g_b62sem)) < 0)
{ {
DEBUGASSERT(errno == EINTR); DEBUGASSERT(errno == EINTR);
} }

View File

@ -213,6 +213,7 @@ loop:
swap(pl, pl - size); swap(pl, pl - size);
} }
} }
return; return;
} }
@ -230,6 +231,7 @@ loop:
if ((r = pd - pc) > size) if ((r = pd - pc) > size)
{ {
/* Iterate rather than recurse to save stack space */ /* Iterate rather than recurse to save stack space */
base = pn - r; base = pn - r;
nmemb = r / size; nmemb = r / size;
goto loop; goto loop;

View File

@ -91,7 +91,7 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
/* Handle bad sizes */ /* Handle bad sizes */
if (size <= 0) if (size < 1)
{ {
return NULL; return NULL;
} }

View File

@ -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 is zero, then realloc is equivalent to free */
if (size <= 0) if (size < 1)
{ {
mm_free(heap, oldmem); mm_free(heap, oldmem);
return NULL; 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. * 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? */ /* Can we get everything we need from the previous chunk? */