From 9ba725c3d486dd28fe9b2489b0f95a65354d7d86 Mon Sep 17 00:00:00 2001 From: lnlan Date: Fri, 12 Nov 2021 07:32:39 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20A=E6=A0=B8=E4=BB=A3=E7=A0=81=E9=9D=99?= =?UTF-8?q?=E6=80=81=E5=91=8A=E8=AD=A6=E5=AE=9A=E6=9C=9F=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【背景】A核代码静态告警定期清理 【修改方案】 1,根据codex等工具分析结果,进行必要的规范等问题修改 【影响】 对现有的产品编译不会有影响。 re #I4I0O8 Signed-off-by: wangchen <253227059@qq.com> --- apps/perf/src/perf.c | 2 +- apps/shell/include/shmsg.h | 4 +- apps/shell/src/main.c | 4 +- apps/shell/src/shmsg.c | 2 +- apps/trace/src/trace.c | 22 ++++--- arch/arm/arm/src/smp.c | 2 +- compat/posix/src/stdlib.c | 2 +- fs/proc/os_adapt/fs_cache_proc.c | 12 ++-- fs/vfs/epoll/fs_epoll.c | 21 ++++--- fs/vfs/include/epoll.h | 12 ++-- fs/vfs/operation/vfs_check.c | 2 +- fs/vfs/operation/vfs_fallocate.c | 13 ++-- fs/vfs/operation/vfs_fallocate64.c | 11 ++-- fs/vfs/operation/vfs_other.c | 34 ++++------ kernel/common/console.c | 5 +- kernel/extended/dynload/src/los_load_elf.c | 2 +- kernel/extended/liteipc/hm_liteipc.c | 8 ++- kernel/extended/trace/cnv/trace_cnv.c | 2 +- lib/libc/src/memcmp.c | 38 ++++++----- lib/libc/src/memset.c | 73 +++++++++++++--------- shell/full/src/cmds/watch_shellcmd.c | 2 +- syscall/fs_syscall.c | 6 +- 22 files changed, 144 insertions(+), 135 deletions(-) diff --git a/apps/perf/src/perf.c b/apps/perf/src/perf.c index fdcf0b4e..aeafec0e 100644 --- a/apps/perf/src/perf.c +++ b/apps/perf/src/perf.c @@ -70,7 +70,7 @@ static void PerfSetPeriod(PerfConfigAttr *attr) void PerfPrintBuffer(const char *buf, ssize_t num) { #define BYTES_PER_LINE 4 - ssize_t i = 0; + ssize_t i; for (i = 0; i < num; i++) { printf(" %02x", (unsigned char)buf[i]); if (((i + 1) % BYTES_PER_LINE) == 0) { diff --git a/apps/shell/include/shmsg.h b/apps/shell/include/shmsg.h index d9c172a2..4bc60261 100644 --- a/apps/shell/include/shmsg.h +++ b/apps/shell/include/shmsg.h @@ -46,7 +46,7 @@ extern "C" { #define SHELL_EXEC_COMMAND "exec" #define SHELL_EXEC_COMMAND_BYTES 4 #define CMD_EXEC_COMMAND SHELL_EXEC_COMMAND" " -#define CMD_EXEC_COMMAND_BYTES (SHELL_EXEC_COMMAND_BYTES+1) +#define CMD_EXEC_COMMAND_BYTES (SHELL_EXEC_COMMAND_BYTES + 1) #define CMD_EXIT_COMMAND "exit" #define CMD_EXIT_COMMAND_BYTES 4 #define CMD_EXIT_CODE_BASE_DEC 10 @@ -59,7 +59,7 @@ extern "C" { #define COLOR_L_RED "\e[1;31m" #define SHELL_PROMPT COLOR_L_RED"OHOS # "COLOR_NONE -typedef void (*OutputFunc)(const char *fmt, ...); +typedef void (* OutputFunc)(const char *fmt, ...); extern int ShellTaskInit(ShellCB *shellCB); extern int ShellEntryInit(ShellCB *shellCB); extern void ChildExec(const char *cmdName, char *const paramArray[]); diff --git a/apps/shell/src/main.c b/apps/shell/src/main.c index 1a691988..d1a465f5 100644 --- a/apps/shell/src/main.c +++ b/apps/shell/src/main.c @@ -110,12 +110,12 @@ static int DoShellExec(char **argv) } memset_s(cmdLine, len, 0, len); - for(j = 0; j < i; j++) { + for (j = 0; j < i; j++) { strcat_s(cmdLine, len, argv[j]); strcat_s(cmdLine, len, " "); } - cmdLine[len - 2] = '\0'; + cmdLine[len - 2] = '\0'; /* 2, (len - 2) is the end of cmdline buf */ ret = syscall(__NR_shellexec, argv[0], cmdLine); free(cmdLine); return ret; diff --git a/apps/shell/src/shmsg.c b/apps/shell/src/shmsg.c index 320e60b4..e8e8f34e 100644 --- a/apps/shell/src/shmsg.c +++ b/apps/shell/src/shmsg.c @@ -391,7 +391,7 @@ int CheckExit(const char *cmdName, const CmdParsed *cmdParsed) return -1; } if (cmdParsed->paramCnt == 1) { - char *p; + char *p = NULL; ret = strtol(cmdParsed->paramArray[0], &p, CMD_EXIT_CODE_BASE_DEC); if (*p != '\0') { printf("exit: bad number: %s\n", cmdParsed->paramArray[0]); diff --git a/apps/trace/src/trace.c b/apps/trace/src/trace.c index ab307f79..1b1f4b07 100644 --- a/apps/trace/src/trace.c +++ b/apps/trace/src/trace.c @@ -88,11 +88,13 @@ static void TraceWrite(int fd, int argc, char **argv) { int i; UsrEventInfo info = {0}; - info.eventType = strtoul(argv[2], NULL, 0); - info.identity = strtoul(argv[3], NULL, 0); + info.eventType = strtoul(argv[2], NULL, 0); /* 2, argv number */ + info.identity = strtoul(argv[3], NULL, 0); /* 3, argv number */ + /* 4, argc -4 means user argv that does not contain argv[0]~argv[3] */ int paramNum = (argc - 4) > TRACE_USR_MAX_PARAMS ? TRACE_USR_MAX_PARAMS : (argc - 4); - + for (i = 0; i < paramNum; i++) { + /* 4, argc -4 means user argv that does not contain argv[0]~argv[3] */ info.params[i] = strtoul(argv[4 + i], NULL, 0); } (void)write(fd, &info, sizeof(UsrEventInfo)); @@ -108,22 +110,22 @@ int main(int argc, char **argv) if (argc == 1) { TraceUsage(); - } else if (argc == 2 && strcmp(argv[1], "start") == 0) { + } else if (argc == 2 && strcmp(argv[1], "start") == 0) { /* 2, argv num, no special meaning */ ioctl(fd, TRACE_START, NULL); - } else if (argc == 2 && strcmp(argv[1], "stop") == 0) { + } else if (argc == 2 && strcmp(argv[1], "stop") == 0) { /* 2, argv num, no special meaning */ ioctl(fd, TRACE_STOP, NULL); - } else if (argc == 2 && strcmp(argv[1], "reset") == 0) { + } else if (argc == 2 && strcmp(argv[1], "reset") == 0) { /* 2, argv num, no special meaning */ ioctl(fd, TRACE_RESET, NULL); - } else if (argc == 3 && strcmp(argv[1], "mask") == 0) { + } else if (argc == 3 && strcmp(argv[1], "mask") == 0) { /* 3, argv num, no special meaning */ size_t mask = strtoul(argv[2], NULL, 0); ioctl(fd, TRACE_SET_MASK, mask); - } else if (argc == 3 && strcmp(argv[1], "dump") == 0) { + } else if (argc == 3 && strcmp(argv[1], "dump") == 0) { /* 3, argv num, no special meaning */ size_t flag = strtoul(argv[2], NULL, 0); ioctl(fd, TRACE_DUMP, flag); - } else if (argc == 3 && strcmp(argv[1], "read") == 0) { + } else if (argc == 3 && strcmp(argv[1], "read") == 0) { /* 3, argv num, no special meaning */ size_t size = strtoul(argv[2], NULL, 0); TraceRead(fd, size); - } else if (argc >= 4 && strcmp(argv[1], "write") == 0) { + } else if (argc >= 4 && strcmp(argv[1], "write") == 0) { /* 4, argv num, no special meaning */ TraceWrite(fd, argc, argv); } else { printf("Unsupported trace command.\n"); diff --git a/arch/arm/arm/src/smp.c b/arch/arm/arm/src/smp.c index a747a744..267a9008 100644 --- a/arch/arm/arm/src/smp.c +++ b/arch/arm/arm/src/smp.c @@ -55,7 +55,7 @@ VOID HalArchCpuOn(UINT32 cpuNum, ArchCpuStartFunc func, struct SmpOps *ops, VOID { struct OsCpuInit *cpuInit = &g_cpuInit[cpuNum - 1]; UINTPTR startEntry = (UINTPTR)&reset_vector - KERNEL_VMM_BASE + SYS_MEM_BASE; - INT32 ret = 0; + INT32 ret; cpuInit->cpuStart = func; cpuInit->arg = arg; diff --git a/compat/posix/src/stdlib.c b/compat/posix/src/stdlib.c index f4a90263..cbab4f7d 100644 --- a/compat/posix/src/stdlib.c +++ b/compat/posix/src/stdlib.c @@ -47,7 +47,7 @@ void srand(unsigned s) int rand(void) { - return random(); + return random(); } void _exit(int status) diff --git a/fs/proc/os_adapt/fs_cache_proc.c b/fs/proc/os_adapt/fs_cache_proc.c index 9ba8917c..a33ec1a9 100644 --- a/fs/proc/os_adapt/fs_cache_proc.c +++ b/fs/proc/os_adapt/fs_cache_proc.c @@ -136,16 +136,16 @@ static int PageCacheMapProcess(struct SeqBuf *buf) static int FsCacheInfoFill(struct SeqBuf *buf, void *arg) { - int vnodeFree = 0; - int vnodeActive = 0; - int vnodeVirtual = 0; - int vnodeTotal = 0; + int vnodeFree; + int vnodeActive; + int vnodeVirtual; + int vnodeTotal; - int pathCacheTotal = 0; + int pathCacheTotal; int pathCacheTotalTry = 0; int pathCacheTotalHit = 0; - int pageCacheTotal = 0; + int pageCacheTotal; int pageCacheTotalTry = 0; int pageCacheTotalHit = 0; diff --git a/fs/vfs/epoll/fs_epoll.c b/fs/vfs/epoll/fs_epoll.c index d59e7cdf..1eeec53a 100755 --- a/fs/vfs/epoll/fs_epoll.c +++ b/fs/vfs/epoll/fs_epoll.c @@ -71,8 +71,8 @@ static int EpollAllocSysFd(int maxfdp, struct epoll_head *head) fd_set *fdset = &g_epollFdSet; for (i = 0; i < maxfdp; i++) { - if (fdset && !(FD_ISSET(i + EPOLL_FD_OFFSET, fdset))) { - FD_SET(i + EPOLL_FD_OFFSET, fdset); + if (fdset && !(FD_ISSET(i, fdset))) { + FD_SET(i, fdset); if (!g_epPrivBuf[i]) { g_epPrivBuf[i] = head; return i + EPOLL_FD_OFFSET; @@ -92,17 +92,17 @@ static int EpollAllocSysFd(int maxfdp, struct epoll_head *head) */ static int EpollFreeSysFd(int fd) { - int id = fd - EPOLL_FD_OFFSET; + int efd = fd - EPOLL_FD_OFFSET; - if ((id < 0) || (id >= MAX_EPOLL_FD)) { + if ((efd < 0) || (efd >= MAX_EPOLL_FD)) { set_errno(EMFILE); return -1; } fd_set *fdset = &g_epollFdSet; - if (fdset && FD_ISSET(fd, fdset)) { - FD_CLR(id, fdset); - g_epPrivBuf[id] = NULL; + if (fdset && FD_ISSET(efd, fdset)) { + FD_CLR(efd, fdset); + g_epPrivBuf[efd] = NULL; } return 0; @@ -159,7 +159,8 @@ static VOID DoEpollClose(struct epoll_head *epHead) free(epHead); } - return ; + + return; } /** @@ -236,7 +237,7 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev) int ret = -1; epHead = EpollGetDataBuff(epfd); - if (epHead== NULL) { + if (epHead == NULL) { set_errno(EBADF); return ret; } @@ -328,6 +329,7 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout ret = poll(pFd, pollSize, timeout); if (ret <= 0) { + free(pFd); return 0; } @@ -339,6 +341,7 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout } } + free(pFd); return i; } diff --git a/fs/vfs/include/epoll.h b/fs/vfs/include/epoll.h index 70f75f64..c6f6ff3a 100755 --- a/fs/vfs/include/epoll.h +++ b/fs/vfs/include/epoll.h @@ -61,15 +61,15 @@ extern "C" { #define EPOLL_CTL_MOD 3 typedef union epoll_data { - void *ptr; - int fd; - UINT32 u32; - UINT64 u64; + void *ptr; + int fd; + UINT32 u32; + UINT64 u64; } epoll_data_t; struct epoll_event { - UINT32 events; - epoll_data_t data; + UINT32 events; + epoll_data_t data; }; int epoll_create(int size); diff --git a/fs/vfs/operation/vfs_check.c b/fs/vfs/operation/vfs_check.c index ae86d83a..d4aed072 100644 --- a/fs/vfs/operation/vfs_check.c +++ b/fs/vfs/operation/vfs_check.c @@ -63,7 +63,7 @@ int fscheck(const char *path) dir = (struct fs_dirent_s *)zalloc(sizeof(struct fs_dirent_s)); if (!dir) { - /* Insufficient memory to complete the operation.*/ + /* Insufficient memory to complete the operation. */ ret = -ENOMEM; VnodeDrop(); goto errout; diff --git a/fs/vfs/operation/vfs_fallocate.c b/fs/vfs/operation/vfs_fallocate.c index d68eeac5..320df2d3 100644 --- a/fs/vfs/operation/vfs_fallocate.c +++ b/fs/vfs/operation/vfs_fallocate.c @@ -120,23 +120,20 @@ int fallocate(int fd, int mode, off_t offset, off_t len) #if CONFIG_NFILE_DESCRIPTORS > 0 - /* The descriptor is in the right range to be a file descriptor... write to the file.*/ + /* The descriptor is in the right range to be a file descriptor... write to the file. */ int ret = fs_getfilep(fd, &filep); - if (ret < 0) - { + if (ret < 0) { /* The errno value has already been set */ return VFS_ERROR; - } + } - if (filep->f_oflags & O_DIRECTORY) - { + if (filep->f_oflags & O_DIRECTORY) { set_errno(EBADF); return VFS_ERROR; - } + } /* Perform the fallocate operation using the file descriptor as an index */ - return file_fallocate(filep, mode, offset, len); #endif } diff --git a/fs/vfs/operation/vfs_fallocate64.c b/fs/vfs/operation/vfs_fallocate64.c index 0560feef..bd56f5f9 100644 --- a/fs/vfs/operation/vfs_fallocate64.c +++ b/fs/vfs/operation/vfs_fallocate64.c @@ -128,20 +128,17 @@ int fallocate64(int fd, int mode, off64_t offset, off64_t len) */ int ret = fs_getfilep(fd, &filep); - if (ret < 0) - { + if (ret < 0) { /* The errno value has already been set */ return VFS_ERROR; - } + } - if (filep->f_oflags & O_DIRECTORY) - { + if (filep->f_oflags & O_DIRECTORY) { set_errno(EBADF); return VFS_ERROR; - } + } /* Perform the fallocate operation using the file descriptor as an index */ - return file_fallocate64(filep, mode, offset, len); #endif } diff --git a/fs/vfs/operation/vfs_other.c b/fs/vfs/operation/vfs_other.c index 49358049..99a513d3 100644 --- a/fs/vfs/operation/vfs_other.c +++ b/fs/vfs/operation/vfs_other.c @@ -84,6 +84,7 @@ int VfsVnodePermissionCheck(const struct Vnode *node, int accMode) uint fileMode = node->mode; return VfsPermissionCheck(fuid, fgid, fileMode, accMode); } + int VfsPermissionCheck(uint fuid, uint fgid, uint fileMode, int accMode) { uint uid = OsCurrUserGet()->effUserID; @@ -196,11 +197,10 @@ int chdir(const char *path) #ifdef VFS_USING_WORKDIR ret = SetWorkDir(fullpath, strlen(fullpath)); - if (ret != 0) - { + if (ret != 0) { PRINT_ERR("chdir path error!\n"); ret = -1; - } + } #endif /* release normalize directory path name */ @@ -235,19 +235,17 @@ char *getcwd(char *buf, size_t n) #ifdef VFS_USING_WORKDIR spin_lock_irqsave(&curr->files->workdir_lock, lock_flags); len = strlen(curr->files->workdir); - if (n <= len) - { + if (n <= len) { set_errno(ERANGE); spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags); return NULL; - } + } ret = memcpy_s(buf, n, curr->files->workdir, len + 1); - if (ret != EOK) - { + if (ret != EOK) { set_errno(ENAMETOOLONG); spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags); return NULL; - } + } spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags); #else PRINT_ERR("NO_WORKING_DIR\n"); @@ -393,8 +391,7 @@ static struct dirent **scandir_get_file_list(const char *dir, int *num, int(*fil int scandir(const char *dir, struct dirent ***namelist, int(*filter)(const struct dirent *), - int(*compar)(const struct dirent **, - const struct dirent **)) + int(*compar)(const struct dirent **, const struct dirent **)) { int n = 0; struct dirent **list = NULL; @@ -409,7 +406,6 @@ int scandir(const char *dir, struct dirent ***namelist, } /* Change to return to the array size */ - *namelist = (struct dirent **)malloc(n * sizeof(struct dirent *)); if (*namelist == NULL && n > 0) { *namelist = list; @@ -447,18 +443,16 @@ char *rindex(const char *s, int c) static char *ls_get_fullpath(const char *path, struct dirent *pdirent) { char *fullpath = NULL; - int ret = 0; + int ret; if (path[1] != '\0') { - /* 2: The position of the path character: / and the end character /0 */ - + /* 2, The position of the path character: / and the end character '/0' */ fullpath = (char *)malloc(strlen(path) + strlen(pdirent->d_name) + 2); if (fullpath == NULL) { goto exit_with_nomem; } - /* 2: The position of the path character: / and the end character /0 */ - + /* 2, The position of the path character: / and the end character '/0' */ ret = snprintf_s(fullpath, strlen(path) + strlen(pdirent->d_name) + 2, strlen(path) + strlen(pdirent->d_name) + 1, "%s/%s", path, pdirent->d_name); if (ret < 0) { @@ -467,15 +461,13 @@ static char *ls_get_fullpath(const char *path, struct dirent *pdirent) return NULL; } } else { - /* 2: The position of the path character: / and the end character /0 */ - + /* 2, The position of the path character: / and the end character '/0' */ fullpath = (char *)malloc(strlen(pdirent->d_name) + 2); if (fullpath == NULL) { goto exit_with_nomem; } - /* 2: The position of the path character: / and the end character /0 */ - + /* 2, The position of the path character: / and the end character '/0' */ ret = snprintf_s(fullpath, strlen(pdirent->d_name) + 2, strlen(pdirent->d_name) + 1, "/%s", pdirent->d_name); if (ret < 0) { diff --git a/kernel/common/console.c b/kernel/common/console.c index 1eb47103..289683de 100644 --- a/kernel/common/console.c +++ b/kernel/common/console.c @@ -444,7 +444,8 @@ VOID KillPgrp(UINT16 consoleId) if ((consoleId > CONSOLE_NUM) || (consoleId <= 0)) { return; } - CONSOLE_CB *consoleCB = g_console[consoleId-1]; + + CONSOLE_CB *consoleCB = g_console[consoleId - 1]; /* the default of consoleCB->pgrpId is -1, may not be set yet, avoid killing all processes */ if (consoleCB->pgrpId < 0) { return; @@ -1445,7 +1446,7 @@ BOOL ConsoleEnable(VOID) BOOL IsShellEntryRunning(UINT32 shellEntryId) { - LosTaskCB *taskCB; + LosTaskCB *taskCB = NULL; if (shellEntryId == SHELL_ENTRYID_INVALID) { return FALSE; } diff --git a/kernel/extended/dynload/src/los_load_elf.c b/kernel/extended/dynload/src/los_load_elf.c index 6685bdbd..5507cb27 100644 --- a/kernel/extended/dynload/src/los_load_elf.c +++ b/kernel/extended/dynload/src/los_load_elf.c @@ -225,7 +225,7 @@ STATIC INT32 OsReadEhdr(const CHAR *fileName, ELFInfo *elfInfo, BOOL isExecFile) #ifdef LOSCFG_DRIVERS_TZDRIVER if (isExecFile) { - struct file *filep; + struct file *filep = NULL; ret = fs_getfilep(GetAssociatedSystemFd(elfInfo->procfd), &filep); if (ret) { PRINT_ERR("%s[%d], Failed to get struct file %s!\n", __FUNCTION__, __LINE__, fileName); diff --git a/kernel/extended/liteipc/hm_liteipc.c b/kernel/extended/liteipc/hm_liteipc.c index 26b6352a..f9632599 100644 --- a/kernel/extended/liteipc/hm_liteipc.c +++ b/kernel/extended/liteipc/hm_liteipc.c @@ -239,8 +239,10 @@ LITE_OS_SEC_TEXT STATIC int LiteIpcMmap(struct file *filep, LosVmMapRegion *regi ERROR_MAP_OUT: LOS_VFree(ipcInfo->pool.kvaddr); ERROR_REGION_OUT: - ipcInfo->pool.uvaddr = NULL; - ipcInfo->pool.kvaddr = NULL; + if (ipcInfo != NULL) { + ipcInfo->pool.uvaddr = NULL; + ipcInfo->pool.kvaddr = NULL; + } return ret; } @@ -979,7 +981,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 CheckPara(IpcContent *content, UINT32 *dstTid) } #endif OsHookCall(LOS_HOOK_TYPE_IPC_WRITE_DROP, msg, *dstTid, - (*dstTid == INVAILD_ID) ? INVAILD_ID : OS_TCB_FROM_TID(*dstTid)->processID, 0); + (*dstTid == INVAILD_ID) ? INVAILD_ID : OS_TCB_FROM_TID(*dstTid)->processID, 0); PRINT_ERR("Liteipc A timeout reply, request timestamp:%lld, now:%lld\n", msg->timestamp, now); return -ETIME; } diff --git a/kernel/extended/trace/cnv/trace_cnv.c b/kernel/extended/trace/cnv/trace_cnv.c index cb67b112..3353f4ad 100644 --- a/kernel/extended/trace/cnv/trace_cnv.c +++ b/kernel/extended/trace/cnv/trace_cnv.c @@ -262,7 +262,7 @@ STATIC VOID LOS_TraceUsrEvent(VOID *buffer, UINT32 len) return; } LOS_TRACE_EASY(info->eventType & (~TRACE_USER_DEFAULT_FLAG), info->identity, info->params[0], info->params[1], - info->params[2]); + info->params[2]); /* 2, params num, no special meaning */ LOS_MemFree(m_aucSysMem0, buffer); #endif } diff --git a/lib/libc/src/memcmp.c b/lib/libc/src/memcmp.c index c3a0f873..fce4dab7 100644 --- a/lib/libc/src/memcmp.c +++ b/lib/libc/src/memcmp.c @@ -36,39 +36,43 @@ int memcmp(const void *str1, const void *str2, size_t n) const unsigned char *s1 = str1; const unsigned char *s2 = str2; + size_t num = n; - while (n >= 8) { + while (num >= 8) { /* 8, compare size, the number of chars of one uint64_t data */ if (*(const uint64_t *)(s1) != *(const uint64_t *)(s2)) { goto L8_byte_diff; } - s1 += 8; - s2 += 8; - n -= 8; + s1 += 8; /* 8, compare size, the number of chars of one uint64_t data */ + s2 += 8; /* 8, compare size, the number of chars of one uint64_t data */ + num -= 8; /* 8, compare size, the number of chars of one uint64_t data */ + } + if (num == 0) { + return 0; } - if (n == 0) return 0; - /* L4_byte_cmp */ - if (n >= 4) { + if (num >= 4) { /* 4, compare size, the number of chars of one uint32_t data */ if (*(const uint32_t *)(s1) != *(const uint32_t *)(s2)) { goto L4_byte_diff; } - s1 += 4; - s2 += 4; - n -= 4; + s1 += 4; /* 4, compare size, the number of chars of one uint32_t data */ + s2 += 4; /* 4, compare size, the number of chars of one uint32_t data */ + num -= 4; /* 4, compare size, the number of chars of one uint32_t data */ + } + if (num == 0) { + return 0; } - if (n == 0) return 0; - L4_byte_diff: - for (; n && (*s1 == *s2); n--, s1++, s2++); - return n ? *s1 - *s2 : 0; + for (; num && (*s1 == *s2); num--, s1++, s2++) { + } + return num ? *s1 - *s2 : 0; L8_byte_diff: if (*(const uint32_t *)(s1) != *(const uint32_t *)(s2)) { goto L4_byte_diff; } - s1 += 4; - s2 += 4; - n -= 4; + s1 += 4; /* 4, compare size, the number of chars of one uint32_t data */ + s2 += 4; /* 4, compare size, the number of chars of one uint32_t data */ + num -= 4; /* 4, compare size, the number of chars of one uint32_t data */ goto L4_byte_diff; } \ No newline at end of file diff --git a/lib/libc/src/memset.c b/lib/libc/src/memset.c index 213721d5..8bf07fc9 100644 --- a/lib/libc/src/memset.c +++ b/lib/libc/src/memset.c @@ -38,25 +38,28 @@ void *memset(void *dest, int c, size_t n) char *pos = dest; uint32_t c32 = 0; uint64_t c64 = 0; + size_t num = n; - if (n == 0) return dest; + if (num == 0) { + return dest; + } c = c & 0xFF; if (c) { c32 = c; - c32 |= c32 << 8; - c32 |= c32 << 16; + c32 |= c32 << 8; /* 8, Processed bits */ + c32 |= c32 << 16; /* 16, Processed bits */ c64 = c32; - c64 |= c64 << 32; + c64 |= c64 << 32; /* 32, Processed bits */ } - if (((uintptr_t)(pos) & 7) != 0) { - int unalignedCnt = 8 - ((uintptr_t)(pos) & 7); - if (n >= unalignedCnt) { - n = n - unalignedCnt; + if (((uintptr_t)(pos) & 7) != 0) { /* 7, Processed align */ + int unalignedCnt = 8 - ((uintptr_t)(pos) & 7); /* 7, 8, for calculate addr bits align */ + if (num >= unalignedCnt) { + num = num - unalignedCnt; } else { - unalignedCnt = n; - n = 0; + unalignedCnt = num; + num = 0; } for (int loop = 1; loop <= unalignedCnt; ++loop) { *pos = (char)c; @@ -65,41 +68,49 @@ void *memset(void *dest, int c, size_t n) } /* L32_byte_aligned */ - while (n >= 32) { + while (num >= 32) { /* 32, byte aligned */ *(uint64_t *)(pos) = c64; - *(uint64_t *)(pos + 8) = c64; - *(uint64_t *)(pos + 16) = c64; - *(uint64_t *)(pos + 24) = c64; - n -= 32; - pos += 32; + *(uint64_t *)(pos + 8) = c64; /* 8, size of uint64_t */ + *(uint64_t *)(pos + 16) = c64; /* 16, size of two uint64_t data */ + *(uint64_t *)(pos + 24) = c64; /* 24, size of three uint64_t data */ + num -= 32; /* 32, size of four uint64_t data */ + pos += 32; /* 32, size of four uint64_t data */ + } + if (num == 0) { + return dest; } - if (n == 0) return dest; /* L16_byte_aligned */ - if (n >= 16) { + if (num >= 16) { /* 16, byte aligned */ *(uint64_t *)(pos) = c64; - *(uint64_t *)(pos + 8) = c64; - n -= 16; - pos += 16; - if (n == 0) return dest; + *(uint64_t *)(pos + 8) = c64; /* 8, size of uint64_t */ + num -= 16; /* 16, size of two uint64_t data */ + pos += 16; /* 16, size of two uint64_t data */ + if (num == 0) { + return dest; + } } /* L8_byte_aligned */ - if (n >= 8) { + if (num >= 8) { /* 8, byte aligned */ *(uint64_t *)(pos) = c64; - n -= 8; - pos += 8; - if (n == 0) return dest; + num -= 8; /* 8, size of uint64_t */ + pos += 8; /* 8, size of uint64_t */ + if (num == 0) { + return dest; + } } /* L4_byte_aligned */ - if (n >= 4) { + if (num >= 4) { /* 4, byte aligned */ *(uint32_t *)(pos) = c32; - n -= 4; - pos += 4; - if (n == 0) return dest; + num -= 4; /* 4, size of uint32_t */ + pos += 4; /* 4, size of uint32_t */ + if (num == 0) { + return dest; + } } - while (n--) { + while (num--) { *pos++ = c; } diff --git a/shell/full/src/cmds/watch_shellcmd.c b/shell/full/src/cmds/watch_shellcmd.c index 88e67f57..88c72726 100644 --- a/shell/full/src/cmds/watch_shellcmd.c +++ b/shell/full/src/cmds/watch_shellcmd.c @@ -217,7 +217,7 @@ UINT32 OsShellCmdWatch(UINT32 argc, const CHAR **argv) { WatchCB *watchItem = NULL; UINT32 argoff = 0; - UINT32 ret = 0; + UINT32 ret; INT32 err; if (argc == 0) { diff --git a/syscall/fs_syscall.c b/syscall/fs_syscall.c index acd54a9d..ba787462 100755 --- a/syscall/fs_syscall.c +++ b/syscall/fs_syscall.c @@ -2503,7 +2503,7 @@ int SysFstatfs(int fd, struct statfs *buf) int SysFstatfs64(int fd, size_t sz, struct statfs *buf) { - int ret = 0; + int ret; if (sz != sizeof(struct statfs)) { ret = -EINVAL; @@ -2654,13 +2654,13 @@ int SysEpollCtl(int epfd, int op, int fd, struct epoll_event *ev) ret = epoll_ctl(epfd, op, fd, ev); if (ret < 0) { - ret =-EBADF; + ret = -EBADF; goto OUT; } CPY_TO_USER(ev); OUT: - return (ret == -1)? -get_errno():ret; + return (ret == -1) ? -get_errno() : ret; } int SysEpollWait(int epfd, struct epoll_event *evs, int maxevents, int timeout)