Various changes and bigfixes for problems detected by CppCheck

This commit is contained in:
Gregory Nutt
2013-05-09 14:23:34 -06:00
parent c9fcc7eef4
commit 88c0911fb1
25 changed files with 126 additions and 69 deletions
+6 -3
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/arm/src/imx/imx_spi.c
*
* Copyright (C) 2009-2010 Gregory Nutt. All rights reserved.
* Copyright (C) 2009-2010, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -728,9 +728,12 @@ static int spi_lock(FAR struct spi_dev_s *dev, bool lock)
static uint32_t spi_setfrequency(FAR struct spi_dev_s *dev, uint32_t frequency)
{
struct imx_spidev_s *priv = (struct imx_spidev_s *)dev;
uint32_t actual = priv->actual;
uint32_t actual;
if (priv && frequency != priv->frequency)
DEBUGASSERT(priv);
actual = priv->actual;
if (frequency != priv->frequency)
{
uint32_t freqbits;
uint32_t regval;
+9 -1
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/arm/src/kinetis/kinetis_pindma.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 201, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -84,6 +84,10 @@ void kinetis_pindmaenable(uint32_t pinset)
DEBUGASSERT(port < KINETIS_NPORTS);
if (port < KINETIS_NPORTS)
{
/* Get the base address of PORT block for this port */
base = KINETIS_PORT_BASE(port);
/* Modify the IRQC field of the port PCR register in order to enable DMA. */
regval = getreg32(base + KINETIS_PORT_PCR_OFFSET(pin));
@@ -134,6 +138,10 @@ void kinetis_pindmadisable(uint32_t pinset)
DEBUGASSERT(port < KINETIS_NPORTS);
if (port < KINETIS_NPORTS)
{
/* Get the base address of PORT block for this port */
base = KINETIS_PORT_BASE(port);
/* Clear the IRQC field of the port PCR register in order to disable DMA. */
regval = getreg32(base + KINETIS_PORT_PCR_OFFSET(pin));
+1 -1
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/arm/src/kinetis/kinetis_pinirq.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
+6 -1
View File
@@ -313,7 +313,8 @@ typedef uint32_t gpio_cfgset_t;
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C" {
extern "C"
{
#else
#define EXTERN extern
#endif
@@ -353,5 +354,9 @@ void kl_gpiowrite(uint32_t pinset, bool value);
bool kl_gpioread(uint32_t pinset);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_ARM_SRC_KL_KINETIS_GPIO_H */
+3 -2
View File
@@ -80,11 +80,10 @@ void up_lowserialinit(void)
uint8_t val;
#ifdef CONFIG_UART0_SERIAL_CONSOLE
/* Set the baudrate */
brg = (freq +(uint32_t)CONFIG_UART0_BAUD * 8) /((uint32_t)CONFIG_UART0_BAUD * 16) ;
/* Set the baudrate */
putreg8(brg >> 8, U0BRH);
putreg8(brg & 0xff, U0BRL);
@@ -107,6 +106,8 @@ void up_lowserialinit(void)
#elif defined(EZ8_UART1) && defined(CONFIG_UART1_SERIAL_CONSOLE)
/* Set the baudrate */
brg = (freq +(uint32_t)CONFIG_UART1_BAUD * 8) /((uint32_t)CONFIG_UART1_BAUD * 16) ;
putreg8(brg >> 8, U1BRH);
putreg8(brg & 0xff, U1BRL);
+9 -9
View File
@@ -256,7 +256,8 @@
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C" {
extern "C"
{
#else
#define EXTERN extern
#endif
@@ -274,7 +275,7 @@ extern "C" {
*
************************************************************************************/
EXTERN void stm32_boardinitialize(void);
void stm32_boardinitialize(void);
/************************************************************************************
* Name: stm32_ledinit, stm32_setled, and stm32_setleds
@@ -287,9 +288,9 @@ EXTERN void stm32_boardinitialize(void);
************************************************************************************/
#ifndef CONFIG_ARCH_LEDS
EXTERN void stm32_ledinit(void);
EXTERN void stm32_setled(int led, bool ledon);
EXTERN void stm32_setleds(uint8_t ledset);
void stm32_ledinit(void);
void stm32_setled(int led, bool ledon);
void stm32_setleds(uint8_t ledset);
#endif
/************************************************************************************
@@ -316,10 +317,10 @@ EXTERN void stm32_setleds(uint8_t ledset);
************************************************************************************/
#ifdef CONFIG_ARCH_BUTTONS
EXTERN void up_buttoninit(void);
EXTERN uint8_t up_buttons(void);
void up_buttoninit(void);
uint8_t up_buttons(void);
#ifdef CONFIG_ARCH_IRQBUTTONS
EXTERN xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
#endif
#endif
@@ -327,6 +328,5 @@ EXTERN xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __CONFIG_MIKROE_STM32F4_INCLUDE_BOARD_H */
@@ -124,7 +124,6 @@
*
* PE10, PMPRD -- Low to read from the LCD
* PE11, PMPWR -- Low to write to the LCD
*
*/
#define GPIO_LCD_RST (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
@@ -226,7 +225,7 @@ void weak_function stm32_usbinitialize(void);
****************************************************************************************************/
#if defined(CONFIG_STM32_OTGFS) && defined(CONFIG_USBHOST)
#error "The Mikroe-STM32F4 board does not support HOST OTG, only device!"
# error "The Mikroe-STM32F4 board does not support HOST OTG, only device!"
#endif
/****************************************************************************************************
+2 -3
View File
@@ -124,7 +124,7 @@ void stm32_board_clockconfig(void)
/* Wait until the PLL is ready */
while ((getreg32(STM32_RCC_CR) & RCC_CR_PLLRDY) == 0)
;
;
/* Enable FLASH prefetch, instruction cache, data cache, and 5 wait states */
@@ -145,7 +145,6 @@ void stm32_board_clockconfig(void)
/* Wait until the PLL source is used as the system clock source */
while ((getreg32(STM32_RCC_CFGR) & RCC_CFGR_SWS_MASK) != RCC_CFGR_SWS_PLL)
;
;
#endif
}
+1 -1
View File
@@ -53,7 +53,7 @@
#include "stm32_can.h"
#include "stm3210e-internal.h"
#if defined(CONFIG_CAN) && (defined(CONFIG_STM32_CAN1)
#if defined(CONFIG_CAN) && defined(CONFIG_STM32_CAN1)
/************************************************************************************
* Pre-processor Definitions
+1 -1
View File
@@ -1135,7 +1135,7 @@ static inline int ssd1289_hwinitialize(FAR struct ssd1289_dev_s *priv)
#if defined(CONFIG_LCD_PORTRAIT) || defined(CONFIG_LCD_RPORTRAIT)
ssd1289_putreg(lcd, SSD1289_OUTCTRL,
(SSD1289_OUTCTRL_MUX(319) | SSD1289_OUTCTRL_TB |
SSD1289_OUTCTRL_BGR | SSD1289_OUTCTRL_REV);
SSD1289_OUTCTRL_BGR | SSD1289_OUTCTRL_REV));
#else
ssd1289_putreg(lcd, SSD1289_OUTCTRL,
(SSD1289_OUTCTRL_MUX(319) | SSD1289_OUTCTRL_BGR |
+1 -1
View File
@@ -571,7 +571,7 @@ static int smartfs_sync_internal(struct smartfs_mountpt_s *fs,
{
struct smart_read_write_s readwrite;
struct smartfs_chain_header_s *header;
int ret;
int ret = OK;
/* Test if we have written bytes to the current sector that
* need to be recorded in the chain header's used bytes field. */
+5
View File
@@ -51,6 +51,11 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifndef CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE
# define CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE 2048
#endif
/* "The spawn.h header shall define the flags that may be set in a
* posix_spawnattr_t object using the posix_spawnattr_setflags() function:"
+1 -5
View File
@@ -48,10 +48,6 @@
* Pre-processor Definitions
****************************************************************************/
#ifndef TASK_SPAWN_DEFAULT_STACKSIZE
# define TASK_SPAWN_DEFAULT_STACKSIZE 2048
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -106,6 +102,6 @@ int posix_spawnattr_init(posix_spawnattr_t *attr)
/* Default stack size */
attr->stacksize = TASK_SPAWN_DEFAULT_STACKSIZE;
attr->stacksize = CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE;
return OK;
}
+2 -1
View File
@@ -130,7 +130,8 @@ int avsprintf(FAR char **ptr, const char *fmt, va_list ap)
/* Then let lib_vsprintf do it's real thing */
nbytes = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, fmt, ap);
nbytes = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public,
fmt, ap);
/* Return a pointer to the string to the caller. NOTE: the memstream put()
* method has already added the NUL terminator to the end of the string (not
+1 -1
View File
@@ -1526,7 +1526,7 @@ int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const char *src, va_list a
/* Get the width of the output */
luwidth = getpsize(FMT_CHAR, flags, p);
pwidth = getpsize(FMT_CHAR, flags, p);
/* Perform left field justification actions */
+2 -1
View File
@@ -93,7 +93,8 @@ int snprintf(FAR char *buf, size_t size, const char *format, ...)
/* Then let lib_vsprintf do the real work */
va_start(ap, format);
n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, format, ap);
n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public,
format, ap);
va_end(ap);
return n;
}
+4 -2
View File
@@ -84,12 +84,14 @@ int sprintf (FAR char *buf, const char *fmt, ...)
/* Initialize a memory stream to write to the buffer */
lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, buf, LIB_BUFLEN_UNKNOWN);
lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, buf,
LIB_BUFLEN_UNKNOWN);
/* Then let lib_vsprintf do the real work */
va_start(ap, fmt);
n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, fmt, ap);
n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public,
fmt, ap);
va_end(ap);
return n;
}
+4 -2
View File
@@ -87,10 +87,12 @@ int vsnprintf(FAR char *buf, size_t size, const char *format, va_list ap)
/* Initialize a memory stream to write to the buffer */
lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, buf, size);
lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream,
buf, size);
/* Then let lib_vsprintf do the real work */
n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, format, ap);
n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public,
format, ap);
return n;
}
+4 -2
View File
@@ -87,6 +87,8 @@ int vsprintf(FAR char *dest, const char *src, va_list ap)
* libc/stdio/lib_vsprintf do the work.
*/
lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, dest, LIB_BUFLEN_UNKNOWN);
return lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, src, ap);
lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, dest,
LIB_BUFLEN_UNKNOWN);
return lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public,
src, ap);
}
+26 -1
View File
@@ -111,6 +111,8 @@ static int task_spawn_exec(FAR pid_t *pidp, FAR const char *name,
main_t entry, FAR const posix_spawnattr_t *attr,
FAR char * const *argv)
{
size_t stacksize;
int priority;
int pid;
int ret = OK;
@@ -121,9 +123,32 @@ static int task_spawn_exec(FAR pid_t *pidp, FAR const char *name,
sched_lock();
/* Use the default task priority and stack size if no attributes are provided */
if (attr)
{
priority = attr->priority;
stacksize = attr->stacksize;
}
else
{
struct sched_param param;
/* Set the default priority to the same priority as this task */
ret = sched_getparam(0, &param);
if (ret < 0)
{
goto errout;
}
priority = param.sched_priority;
stacksize = CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE;
}
/* Start the task */
pid = TASK_CREATE(name, attr->priority, attr->stacksize, entry, argv);
pid = TASK_CREATE(name, priority, stacksize, entry, argv);
if (pid < 0)
{
ret = errno;
+17 -17
View File
@@ -253,26 +253,26 @@ void parse_file(FILE *stream, struct variable_s **list)
curr->val = &curr->storage[varlen];
strcpy(curr->val, varval);
}
}
prev = 0;
next = *list;
while (next && strcmp(next->var, curr->var) <= 0)
{
prev = next;
next = next->flink;
}
prev = 0;
next = *list;
while (next && strcmp(next->var, curr->var) <= 0)
{
prev = next;
next = next->flink;
}
if (prev)
{
prev->flink = curr;
}
else
{
*list = curr;
}
if (prev)
{
prev->flink = curr;
}
else
{
*list = curr;
}
curr->flink = next;
curr->flink = next;
}
}
}
}
+3
View File
@@ -270,5 +270,8 @@ int main(int argc, char **argv, char **envp)
printf("#endif\n\n");
printf("#endif /* __INCLUDE_NUTTX_CONFIG_H */\n");
fclose(stream);
/* Exit (without bothering to clean up allocations) */
return 0;
}
+12 -12
View File
@@ -532,7 +532,6 @@ static void do_dependency(const char *file, char separator)
static char *cywin2windows(const char *str, const char *append, enum slashmode_e mode)
{
static const char cygdrive[] = "/cydrive";
const char *src = src;
char *dest;
char *newpath;
char *allocpath = NULL;
@@ -560,18 +559,19 @@ static char *cywin2windows(const char *str, const char *append, enum slashmode_e
}
snprintf(allocpath, alloclen, "%s/%s", str, append);
str = allocpath;
}
/* Looking for path of the form /cygdrive/c/bla/bla/bla */
if (strcasecmp(src, cygdrive) == 0)
if (strcasecmp(str, cygdrive) == 0)
{
int cygsize = sizeof(cygdrive);
if (src[cygsize] == '/')
if (str[cygsize] == '/')
{
cygsize++;
srclen -= cygsize;
src += cygsize;
str += cygsize;
if (srclen <= 0)
{
@@ -579,7 +579,7 @@ static char *cywin2windows(const char *str, const char *append, enum slashmode_e
exit(EXIT_FAILURE);
}
drive = toupper(*src);
drive = toupper(*str);
if (drive < 'A' || drive > 'Z')
{
fprintf(stderr, "ERROR: Drive charager: \"%s\"\n", str);
@@ -587,18 +587,18 @@ static char *cywin2windows(const char *str, const char *append, enum slashmode_e
}
srclen--;
src++;
str++;
alloclen = 2;
}
}
/* Determine the size of the new path */
alloclen += sizeof(src) + 1;
alloclen += sizeof(str) + 1;
if (mode == MODE_DBLBACK)
{
const char *tmpptr;
for (tmpptr = src; *tmpptr; tmpptr++)
for (tmpptr = str; *tmpptr; tmpptr++)
{
if (*tmpptr == '/') alloclen++;
}
@@ -628,9 +628,9 @@ static char *cywin2windows(const char *str, const char *append, enum slashmode_e
*/
lastchar = '\0';
for (; *src; src++)
for (; *str; str++)
{
if (mode != MODE_FSLASH && *src == '/')
if (mode != MODE_FSLASH && *str == '/')
{
if (lastchar != '/')
{
@@ -643,10 +643,10 @@ static char *cywin2windows(const char *str, const char *append, enum slashmode_e
}
else
{
*dest++ = *src;
*dest++ = *str;
}
lastchar = *src;
lastchar = *str;
}
*dest++ = '\0';
+3
View File
@@ -102,5 +102,8 @@ int main(int argc, char **argv, char **envp)
printf("\n#define CONFIG_VERSION ((CONFIG_VERSION_MAJOR << 8) | (CONFIG_VERSION_MINOR))\n\n");
printf("#endif /* __INCLUDE_NUTTX_VERSION_H */\n");
fclose(stream);
/* Exit (without bothering to clean up allocations) */
return 0;
}
+2
View File
@@ -311,5 +311,7 @@ int main(int argc, char **argv, char **envp)
fprintf(stderr, "Failed to rename '%s' to '%s'\n", destfile, srcfile);
}
/* Exit (without bothering to clean up allocations) */
return 0;
}