diff --git a/arch/arm/cortex-m33/gcc/TZ/non_secure/los_timer.c b/arch/arm/cortex-m33/gcc/TZ/non_secure/los_timer.c index 0432c737..6081ceb3 100644 --- a/arch/arm/cortex-m33/gcc/TZ/non_secure/los_timer.c +++ b/arch/arm/cortex-m33/gcc/TZ/non_secure/los_timer.c @@ -91,7 +91,7 @@ STATIC UINT64 SysTickReload(UINT64 nextResponseTime) STATIC UINT64 SysTickCycleGet(UINT32 *period) { - UINT32 hwCycle = 0; + UINT32 hwCycle = 0; UINT32 intSave = LOS_IntLock(); UINT32 val = SysTick->VAL; *period = SysTick->LOAD; diff --git a/arch/arm/cortex-m33/gcc/TZ/non_secure/los_trustzone.c b/arch/arm/cortex-m33/gcc/TZ/non_secure/los_trustzone.c index 316e6621..13edb833 100644 --- a/arch/arm/cortex-m33/gcc/TZ/non_secure/los_trustzone.c +++ b/arch/arm/cortex-m33/gcc/TZ/non_secure/los_trustzone.c @@ -51,6 +51,7 @@ VOID HalSecureSVCHandler(UINT32 svcID, UINTPTR arg) HalSecureContextLoad(g_secureContext); break; case OS_SVC_FREE_SECURE_CONTEXT: + LOS_ASSERT(g_secureContext != NULL); HalSecureContextFree(g_secureContext); break; default: diff --git a/arch/arm/cortex-m33/iar/TZ/non_secure/los_trustzone.c b/arch/arm/cortex-m33/iar/TZ/non_secure/los_trustzone.c index 316e6621..13edb833 100644 --- a/arch/arm/cortex-m33/iar/TZ/non_secure/los_trustzone.c +++ b/arch/arm/cortex-m33/iar/TZ/non_secure/los_trustzone.c @@ -51,6 +51,7 @@ VOID HalSecureSVCHandler(UINT32 svcID, UINTPTR arg) HalSecureContextLoad(g_secureContext); break; case OS_SVC_FREE_SECURE_CONTEXT: + LOS_ASSERT(g_secureContext != NULL); HalSecureContextFree(g_secureContext); break; default: diff --git a/arch/arm/cortex-m55/gcc/TZ/non_secure/los_timer.c b/arch/arm/cortex-m55/gcc/TZ/non_secure/los_timer.c index 0432c737..6081ceb3 100644 --- a/arch/arm/cortex-m55/gcc/TZ/non_secure/los_timer.c +++ b/arch/arm/cortex-m55/gcc/TZ/non_secure/los_timer.c @@ -91,7 +91,7 @@ STATIC UINT64 SysTickReload(UINT64 nextResponseTime) STATIC UINT64 SysTickCycleGet(UINT32 *period) { - UINT32 hwCycle = 0; + UINT32 hwCycle = 0; UINT32 intSave = LOS_IntLock(); UINT32 val = SysTick->VAL; *period = SysTick->LOAD; diff --git a/arch/arm/cortex-m55/gcc/TZ/non_secure/los_trustzone.c b/arch/arm/cortex-m55/gcc/TZ/non_secure/los_trustzone.c index 316e6621..13edb833 100644 --- a/arch/arm/cortex-m55/gcc/TZ/non_secure/los_trustzone.c +++ b/arch/arm/cortex-m55/gcc/TZ/non_secure/los_trustzone.c @@ -51,6 +51,7 @@ VOID HalSecureSVCHandler(UINT32 svcID, UINTPTR arg) HalSecureContextLoad(g_secureContext); break; case OS_SVC_FREE_SECURE_CONTEXT: + LOS_ASSERT(g_secureContext != NULL); HalSecureContextFree(g_secureContext); break; default: diff --git a/arch/arm/cortex-m55/iar/TZ/non_secure/los_trustzone.c b/arch/arm/cortex-m55/iar/TZ/non_secure/los_trustzone.c index 316e6621..13edb833 100644 --- a/arch/arm/cortex-m55/iar/TZ/non_secure/los_trustzone.c +++ b/arch/arm/cortex-m55/iar/TZ/non_secure/los_trustzone.c @@ -51,6 +51,7 @@ VOID HalSecureSVCHandler(UINT32 svcID, UINTPTR arg) HalSecureContextLoad(g_secureContext); break; case OS_SVC_FREE_SECURE_CONTEXT: + LOS_ASSERT(g_secureContext != NULL); HalSecureContextFree(g_secureContext); break; default: diff --git a/arch/csky/v2/gcc/los_interrupt.c b/arch/csky/v2/gcc/los_interrupt.c index 2bea0454..66c0977a 100644 --- a/arch/csky/v2/gcc/los_interrupt.c +++ b/arch/csky/v2/gcc/los_interrupt.c @@ -612,7 +612,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID) HalHwiHandleReInit((UINT32)&g_hwiForm); HalSetVbr((UINT32)&g_hwiForm); - for (int i = 0; i < BYTES_OF_128_INT; i++) { + for (i = 0; i < BYTES_OF_128_INT; i++) { VIC_REG->IABR[i] = 0x0; VIC_REG->ICPR[i] = MASK_32_BITS; } diff --git a/components/fs/vfs/vfs_fs.c b/components/fs/vfs/vfs_fs.c index a7990a40..a8e95425 100644 --- a/components/fs/vfs/vfs_fs.c +++ b/components/fs/vfs/vfs_fs.c @@ -902,6 +902,10 @@ static int MapToPosixRet(int ret) /* POSIX interface */ int LOS_Open(const char *path, int flags, ...) { + if (path == NULL) { + errno = EINVAL; + return (int)LOS_NOK; + } #ifdef LOSCFG_RANDOM_DEV unsigned flagMask = O_RDONLY | O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_LARGEFILE \ | O_TRUNC | O_EXCL | O_DIRECTORY; @@ -952,7 +956,7 @@ int LOS_Open(const char *path, int flags, ...) FREE_AND_SET_NULL(canonicalPath); #endif #if (LOSCFG_POSIX_PIPE_API == 1) - if ((path != NULL) && !strncmp(path, PIPE_DEV_PATH, strlen(PIPE_DEV_PATH))) { + if (!strncmp(path, PIPE_DEV_PATH, strlen(PIPE_DEV_PATH))) { return PipeOpen(path, flags, PIPE_DEV_FD); } #endif @@ -1149,8 +1153,9 @@ int OsFcntl(int fd, int cmd, va_list ap) ret = VfsVfcntl(filep, cmd, ap); VfsDetachFile(filep); } else { +#ifndef LOSCFG_NET_LWIP_SACK ret = -EBADF; -#ifdef LOSCFG_NET_LWIP_SACK +#else int arg = va_arg(ap, int); ret = lwip_fcntl(fd, (long)cmd, arg); return ret; @@ -1182,8 +1187,9 @@ int OsIoctl(int fd, int req, va_list ap) if (fd < CONFIG_NFILE_DESCRIPTORS) { ret = VfsIoctl(fd, req, ap); } else { +#ifndef LOSCFG_NET_LWIP_SACK ret = -EBADF; -#ifdef LOSCFG_NET_LWIP_SACK +#else UINTPTR arg = va_arg(ap, UINTPTR); ret = lwip_ioctl(fd, (long)req, (void *)arg); #endif /* LOSCFG_NET_LWIP_SACK */ diff --git a/components/fs/vfs/vfs_partition.c b/components/fs/vfs/vfs_partition.c index 28acfb80..367ea1dd 100644 --- a/components/fs/vfs/vfs_partition.c +++ b/components/fs/vfs/vfs_partition.c @@ -47,7 +47,7 @@ int GetPartIdByPartName(const char *partName) /* the character next to p is the partId */ char *p = strrchr(partName, 'p'); - if (p + 1 != NULL) { + if (p != NULL) { return atoi(p + 1); } diff --git a/components/net/lwip-2.1/porting/src/api_shell.c b/components/net/lwip-2.1/porting/src/api_shell.c index c3b20a8f..3e7323f9 100644 --- a/components/net/lwip-2.1/porting/src/api_shell.c +++ b/components/net/lwip-2.1/porting/src/api_shell.c @@ -529,7 +529,7 @@ u32_t OsShellPing(int argc, const char **argv) { int ret; u32_t i = 0; - u32_t count = 0; + u32_t count; int count_set = 0; u32_t interval = 1000; /* default ping interval */ u32_t data_len = 48; /* default data length */ diff --git a/components/security/syscall/pthread_syscall.c b/components/security/syscall/pthread_syscall.c index 5c168e3c..747addcc 100644 --- a/components/security/syscall/pthread_syscall.c +++ b/components/security/syscall/pthread_syscall.c @@ -67,7 +67,7 @@ int SysUserTaskCreate(unsigned long entry, unsigned long userArea, unsigned long int SysSchedSetScheduler(unsigned int tid, int policy, int priority) { - if ((tid <= 0) || (tid > LOSCFG_BASE_CORE_TSK_LIMIT)) { + if ((tid == 0) || (tid > LOSCFG_BASE_CORE_TSK_LIMIT)) { return EINVAL; } @@ -92,7 +92,7 @@ int *SysSchedGetArea(unsigned int tid) unsigned int intSave; int *area = NULL; - if ((tid <= 0) || (tid > LOSCFG_BASE_CORE_TSK_LIMIT)) { + if ((tid == 0) || (tid > LOSCFG_BASE_CORE_TSK_LIMIT)) { return NULL; } diff --git a/components/shell/src/cmds/vfs_shellcmd.c b/components/shell/src/cmds/vfs_shellcmd.c index 73e530f3..801f6e99 100644 --- a/components/shell/src/cmds/vfs_shellcmd.c +++ b/components/shell/src/cmds/vfs_shellcmd.c @@ -544,11 +544,6 @@ STATIC INT32 OsShellCmdDoRmdir(const CHAR *pathname) } if (strcmp(dirent->d_name, "..") && strcmp(dirent->d_name, ".")) { size_t fullPathBufSize = strlen(pathname) + strlen(dirent->d_name) + SEPARATOR_EOF_LEN; - if (fullPathBufSize <= 0) { - PRINTK("buffer size is invalid!\n"); - (VOID)closedir(d); - return -1; - } fullpath = (CHAR *)malloc(fullPathBufSize); if (fullpath == NULL) { PRINTK("malloc failure!\n"); diff --git a/kal/cmsis/cmsis_liteos2.c b/kal/cmsis/cmsis_liteos2.c index 19d389fc..7da55551 100644 --- a/kal/cmsis/cmsis_liteos2.c +++ b/kal/cmsis/cmsis_liteos2.c @@ -978,21 +978,17 @@ osStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id) { PEVENT_CB_S pstEventCB = (PEVENT_CB_S)ef_id; UINT32 intSave; - osStatus_t ret; + osStatus_t ret = osOK; if (OS_INT_ACTIVE) { return osErrorISR; } intSave = LOS_IntLock(); - if (LOS_EventDestroy(pstEventCB) == LOS_OK) { - ret = osOK; - } else { + if (LOS_EventDestroy(pstEventCB) != LOS_OK) { ret = osErrorParameter; } LOS_IntRestore(intSave); - if (LOS_MemFree(m_aucSysMem0, (void *)pstEventCB) == LOS_OK) { - ret = osOK; - } else { + if (LOS_MemFree(m_aucSysMem0, (void *)pstEventCB) != LOS_OK) { ret = osErrorParameter; } diff --git a/kal/posix/src/time.c b/kal/posix/src/time.c index 72b994f0..ce197223 100644 --- a/kal/posix/src/time.c +++ b/kal/posix/src/time.c @@ -501,7 +501,7 @@ time_t time(time_t *timer) { UINT64 usec = 0; time_t sec; - INT32 rtcRet = 0; + INT32 rtcRet; if (g_rtcTimeFunc.RtcGetTimeHook != NULL) { rtcRet = g_rtcTimeFunc.RtcGetTimeHook(&usec); diff --git a/testsuites/unittest/posix/src/fs/posix_fs_func_test.c b/testsuites/unittest/posix/src/fs/posix_fs_func_test.c index e83e03a9..124dc2db 100644 --- a/testsuites/unittest/posix/src/fs/posix_fs_func_test.c +++ b/testsuites/unittest/posix/src/fs/posix_fs_func_test.c @@ -1337,10 +1337,12 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsReaddir002, Function | MediumTest | L dResult = readdir(dirp); TEST_ASSERT_NOT_NULL(dirp); + TEST_ASSERT_NOT_NULL(dResult); tellDir0 = dResult->d_off; dResult = readdir(dirp); TEST_ASSERT_NOT_NULL(dirp); + TEST_ASSERT_NOT_NULL(dResult); tellDir1 = dResult->d_off; TEST_ASSERT_TRUE(tellDir0 == tellDir1); @@ -1496,9 +1498,8 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsStat002, Function | MediumTest | Leve TEST_ASSERT_TRUE(fd != -1); size = write(fd, writeBuf, sizeof(writeBuf)); - TEST_ASSERT_TRUE(ret != -1); - (void)close(fd); + TEST_ASSERT_TRUE(size != -1); ret = stat(tmpFileName, &buf); TEST_ASSERT_TRUE(ret != -1); @@ -1526,8 +1527,8 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsStat003, Function | MediumTest | Leve TEST_ASSERT_TRUE(fd != -1); size = write(fd, writeBuf, sizeof(writeBuf)); - TEST_ASSERT_TRUE(ret != -1); (void)close(fd); + TEST_ASSERT_TRUE(size != -1); ret = stat(tmpFileName, &buf); TEST_ASSERT_TRUE(ret != -1); @@ -1562,18 +1563,24 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsWrite001, Function | MediumTest | Lev TEST_ASSERT_TRUE(fd != -1); ret = write(fd, writeBuf, TEST_RW_SIZE); + if (ret == -1) { + (void)close(fd); + } TEST_ASSERT_TRUE(ret != -1); reLseek = lseek(fd, 0, SEEK_CUR); ret = write(fd, writeBuf, TEST_RW_SIZE); + if (ret == -1) { + (void)close(fd); + } TEST_ASSERT_TRUE(ret != -1); reLseek = lseek(fd, 0, SEEK_CUR); + (void)close(fd); TEST_ASSERT_TRUE((TEST_RW_SIZE + TEST_RW_SIZE) == (unsigned int)reLseek); - (void)close(fd); return 0; } @@ -1598,9 +1605,8 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsWrite002, Function | MediumTest | Lev for (i = 0; i < TEST_LOOPUP_TIME; i++) { ret = write(fd, writeBuf, sizeof(writeBuf)); } - TEST_ASSERT_TRUE(ret != -1); - (void)close(fd); + TEST_ASSERT_TRUE(ret != -1); ret = stat(tmpFileName, &statbuf); TEST_ASSERT_TRUE(ret != -1); diff --git a/testsuites/unittest/posix/src/string/string_func_test_03.c b/testsuites/unittest/posix/src/string/string_func_test_03.c index 12f70473..85f0d5d4 100644 --- a/testsuites/unittest/posix/src/string/string_func_test_03.c +++ b/testsuites/unittest/posix/src/string/string_func_test_03.c @@ -142,6 +142,7 @@ LITE_TEST_CASE(PosixStringFuncTestSuite, testStrStrdup001, Function | MediumTest char src[] = "hello world !"; char *ret = strdup(src); TEST_ASSERT_EQUAL_CHAR_ARRAY(ret, src, sizeof(src) / sizeof(src[0])); + free(ret); char srcS[] = "This is String1"; ret = strdup(srcS);