From d84843f66a19d7bbbad601f8caace4d8af73778a Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Sat, 12 Feb 2022 17:57:46 +0800 Subject: [PATCH] fix: code ReviewBot Signed-off-by: xionglei6 --- interfaces/innerkits/fd_holder/fd_holder.c | 2 +- interfaces/innerkits/fd_holder/fd_holder_internal.c | 2 +- interfaces/innerkits/fs_manager/fstab_mount.c | 3 ++- services/begetctl/param_cmd.c | 2 +- services/begetctl/service_control.c | 1 - services/begetctl/shell/shell_bas.c | 2 +- services/init/include/init.h | 1 + services/init/init_group_manager.c | 4 ++-- services/init/init_service_manager.c | 2 +- services/init/lite/init.c | 1 - services/init/standard/fd_holder_service.c | 4 +++- services/init/standard/init.c | 4 ++-- services/init/standard/init_mount.c | 1 - services/init/standard/init_service.c | 3 +-- services/loopevent/task/le_asynctask.c | 3 +-- services/loopevent/timer/le_timer.c | 4 ++-- services/loopevent/timer/le_timer.h | 2 ++ services/param/trigger/trigger_manager.c | 5 ++--- test/plugintest/plugin_param_test.c | 1 - 19 files changed, 23 insertions(+), 24 deletions(-) diff --git a/interfaces/innerkits/fd_holder/fd_holder.c b/interfaces/innerkits/fd_holder/fd_holder.c index d56af075..04d9f044 100644 --- a/interfaces/innerkits/fd_holder/fd_holder.c +++ b/interfaces/innerkits/fd_holder/fd_holder.c @@ -25,7 +25,7 @@ static int BuildClientSocket(void) { int sockFd; - sockFd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); + sockFd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (sockFd < 0) { BEGET_LOGE("Failed to build socket, err = %d", errno); return -1; diff --git a/interfaces/innerkits/fd_holder/fd_holder_internal.c b/interfaces/innerkits/fd_holder/fd_holder_internal.c index 04dcbc9d..a9ca5dca 100644 --- a/interfaces/innerkits/fd_holder/fd_holder_internal.c +++ b/interfaces/innerkits/fd_holder/fd_holder_internal.c @@ -40,7 +40,7 @@ int BuildControlMessage(struct msghdr *msghdr, int *fds, int fdCount, bool send msghdr->msg_controllen += CMSG_SPACE(sizeof(struct ucred)); } - msghdr->msg_control = calloc(1, (msghdr->msg_controllen == 0 ? 1 : msghdr->msg_controllen)); + msghdr->msg_control = calloc(1, ((msghdr->msg_controllen == 0) ? 1 : msghdr->msg_controllen)); if (msghdr->msg_control == NULL) { BEGET_LOGE("Failed to build control message"); return -1; diff --git a/interfaces/innerkits/fs_manager/fstab_mount.c b/interfaces/innerkits/fs_manager/fstab_mount.c index a55dfdaa..d119c1f4 100644 --- a/interfaces/innerkits/fs_manager/fstab_mount.c +++ b/interfaces/innerkits/fs_manager/fstab_mount.c @@ -170,7 +170,8 @@ static int DoResizeF2fs(const char* device, const unsigned long long size) char **argv = (char **)cmd; ret = ExecCommand(argc, argv); } else { - unsigned long long realSize = size * ((unsigned long long)1024 * 1024 / 512); + unsigned long long realSize = size * + ((unsigned long long)RESIZE_BUFFER_SIZE * RESIZE_BUFFER_SIZE / FS_MANAGER_BUFFER_SIZE); char sizeStr[RESIZE_BUFFER_SIZE] = {0}; sprintf_s(sizeStr, RESIZE_BUFFER_SIZE, "%llu", realSize); char *cmd[] = { diff --git a/services/begetctl/param_cmd.c b/services/begetctl/param_cmd.c index c34d60ec..6a3edd72 100755 --- a/services/begetctl/param_cmd.c +++ b/services/begetctl/param_cmd.c @@ -202,7 +202,7 @@ static int32_t BShellParamCmdLs(BShellHandle shell, int32_t argc, char *argv[]) char *buffer = GetLocalBuffer(&buffSize); char *realParameter = GetRealParameter(shell, (input == NULL) ? "" : input, buffer, buffSize); BSH_CHECK(realParameter != NULL, return BSH_INVALID_PARAM, "Invalid shell env"); - char *prefix = strdup(strlen(realParameter) == 0 ? "#" : realParameter); + char *prefix = strdup((strlen(realParameter) == 0) ? "#" : realParameter); BSH_LOGV("BShellParamCmdLs prefix %s", prefix); int ret = 0; if (all != 0) { diff --git a/services/begetctl/service_control.c b/services/begetctl/service_control.c index 13e25e16..a6213697 100755 --- a/services/begetctl/service_control.c +++ b/services/begetctl/service_control.c @@ -18,7 +18,6 @@ #include #include "begetctl.h" -#include "securec.h" #include "sys_param.h" #define SERVICE_START_NUMBER 2 diff --git a/services/begetctl/shell/shell_bas.c b/services/begetctl/shell/shell_bas.c index 15a0c679..b2e63296 100755 --- a/services/begetctl/shell/shell_bas.c +++ b/services/begetctl/shell/shell_bas.c @@ -152,7 +152,7 @@ void BShellEnvOutputResult(BShellHandle handle, int32_t result) static void BShellEnvOutputParam(BShellHandle handle, char *var) { - BShellEnvOutput(handle, var[0] == '$' ? var + 1 : var); + BShellEnvOutput(handle, (var[0] == '$') ? var + 1 : var); BShellEnvOutputString(handle, " = "); BShellEnvOutputString(handle, BShellEnvGetStringParam(handle, var)); } diff --git a/services/init/include/init.h b/services/init/include/init.h index 966c4d60..b7f5e913 100755 --- a/services/init/include/init.h +++ b/services/init/include/init.h @@ -30,6 +30,7 @@ extern "C" { #define DEFAULT_UID_KIT_FRAMEWORK 3 // max length of one param/path #define MAX_ONE_ARG_LEN 200 +#define FD_HOLDER_BUFFER_SIZE 4096 #define UNUSED(x) (void)(x) diff --git a/services/init/init_group_manager.c b/services/init/init_group_manager.c index ab9659b3..b83458d3 100755 --- a/services/init/init_group_manager.c +++ b/services/init/init_group_manager.c @@ -114,10 +114,10 @@ static char *GetAbsolutePath(const char *path, const char *cfgName, char *buffer ext = strcmp(cfgName + cfgNameLen - strlen(".cfg"), ".cfg") == 0; } if (cfgName[0] != '/') { - const char *format = (ext != 0) ? "%s/%s" : "%s/%s.cfg"; + const char *format = ((ext != 0) ? "%s/%s" : "%s/%s.cfg"); len = sprintf_s(buffer, buffSize, format, path, cfgName); } else { - const char *format = (ext != 0) ? "%s" : "%s.cfg"; + const char *format = ((ext != 0) ? "%s" : "%s.cfg"); len = sprintf_s(buffer, buffSize, format, cfgName); } if (len <= 0) { diff --git a/services/init/init_service_manager.c b/services/init/init_service_manager.c index 7314c1f9..435cc8fe 100755 --- a/services/init/init_service_manager.c +++ b/services/init/init_service_manager.c @@ -274,7 +274,7 @@ static int GetServiceArgs(const cJSON *argJson, const char *name, int maxCount, for (int i = 0; i < count + 1; ++i) { args->argv[i] = NULL; } - // ServiceArgs have a variety of uses, some requiring a NULL ending, some not + // ServiceArgs have a variety of uses, some requiring a NULL ending, some not if (strcmp(name, D_CAPS_STR_IN_CFG) != 0) { args->count = count + 1; } else { diff --git a/services/init/lite/init.c b/services/init/lite/init.c index 2c2d8260..b710f495 100755 --- a/services/init/lite/init.c +++ b/services/init/lite/init.c @@ -22,7 +22,6 @@ #endif #include "loop_event.h" #include "parameter.h" -#include "securec.h" static void PrintSysInfo(void) { diff --git a/services/init/standard/fd_holder_service.c b/services/init/standard/fd_holder_service.c index 26c9eb0e..9f46a3ab 100644 --- a/services/init/standard/fd_holder_service.c +++ b/services/init/standard/fd_holder_service.c @@ -23,6 +23,8 @@ #include "loop_event.h" #include "securec.h" +#define MSG_ARRAY_INDEX 2 + static void FreeFds(int *fds) { if (fds != NULL) { @@ -190,7 +192,7 @@ static void HandlerFdHolder(int sock) } char *serviceName = msg[0]; char *action = msg[1]; - char *pollStr = msg[2]; + char *pollStr = msg[MSG_ARRAY_INDEX]; Service *service = GetServiceByName(serviceName); if (CheckFdHolderPermission(service, requestPid) < 0) { diff --git a/services/init/standard/init.c b/services/init/standard/init.c index 750f3542..35628ac5 100755 --- a/services/init/standard/init.c +++ b/services/init/standard/init.c @@ -47,8 +47,8 @@ static int FdHolderSockInit(void) { int sock = -1; int on = 1; - int fdHolderBufferSize = 4 * 1024; // 4KiB - sock = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); + int fdHolderBufferSize = FD_HOLDER_BUFFER_SIZE; // 4KiB + sock = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0); if (sock < 0) { INIT_LOGE("Failed to create fd holder socket, err = %d", errno); return -1; diff --git a/services/init/standard/init_mount.c b/services/init/standard/init_mount.c index fa45eb44..5782dcc7 100755 --- a/services/init/standard/init_mount.c +++ b/services/init/standard/init_mount.c @@ -16,7 +16,6 @@ #include "fs_manager/fs_manager.h" #include "init_cmds.h" #include "init_log.h" -#include "securec.h" int MountRequriedPartitions(const Fstab *fstab) { diff --git a/services/init/standard/init_service.c b/services/init/standard/init_service.c index f07d00ec..0ecdcbd7 100755 --- a/services/init/standard/init_service.c +++ b/services/init/standard/init_service.c @@ -115,8 +115,7 @@ void GetAccessToken(void) service->capsArgs.argv = NULL; } if (strlen(service->apl) == 0) { - (void)strncpy_s(service->apl, sizeof(service->apl), - "system_core", sizeof(service->apl) - 1); + (void)strncpy_s(service->apl, sizeof(service->apl), "system_core", sizeof(service->apl) - 1); } uint64_t tokenId = GetAccessTokenId(service->name, (const char **)service->capsArgs.argv, service->capsArgs.count, service->apl); diff --git a/services/loopevent/task/le_asynctask.c b/services/loopevent/task/le_asynctask.c index 056b0851..88292089 100755 --- a/services/loopevent/task/le_asynctask.c +++ b/services/loopevent/task/le_asynctask.c @@ -97,8 +97,7 @@ LE_STATUS LE_StartAsyncEvent(const LoopHandle loopHandle, const TaskHandle taskHandle, uint64_t eventId, const uint8_t *data, uint32_t buffLen) { LE_CHECK(loopHandle != NULL && taskHandle != NULL, return LE_INVALID_PARAM, "Invalid parameters"); - BufferHandle handle = NULL; - handle = LE_CreateBuffer(loopHandle, buffLen + 1 + sizeof(eventId)); + BufferHandle handle = LE_CreateBuffer(loopHandle, buffLen + 1 + sizeof(eventId)); char *buff = (char *)LE_GetBufferInfo(handle, NULL, NULL); int ret = memcpy_s(buff, sizeof(eventId), &eventId, sizeof(eventId)); LE_CHECK(ret == 0, return -1, "Failed to copy data"); diff --git a/services/loopevent/timer/le_timer.c b/services/loopevent/timer/le_timer.c index 9d231e03..05ecff4d 100755 --- a/services/loopevent/timer/le_timer.c +++ b/services/loopevent/timer/le_timer.c @@ -27,9 +27,9 @@ static LE_STATUS SetTimer_(int tfd, uint64_t timeout) { struct itimerspec timeValue; - time_t sec = timeout / 1000; + time_t sec = timeout / TIMEOUT_BASE; timeValue.it_interval.tv_sec = sec; - long nsec = (timeout % 1000) * 1000; + long nsec = (timeout % TIMEOUT_BASE) * TIMEOUT_BASE; timeValue.it_interval.tv_nsec = nsec; timeValue.it_value.tv_sec = sec; timeValue.it_value.tv_nsec = nsec; diff --git a/services/loopevent/timer/le_timer.h b/services/loopevent/timer/le_timer.h index 6ed0e18d..8791562d 100755 --- a/services/loopevent/timer/le_timer.h +++ b/services/loopevent/timer/le_timer.h @@ -18,6 +18,8 @@ #include "le_task.h" #include "loop_event.h" +#define TIMEOUT_BASE 1000 + typedef struct { BaseTask base; LE_ProcessTimer processTimer; diff --git a/services/param/trigger/trigger_manager.c b/services/param/trigger/trigger_manager.c index 1a5f4825..dd7dff95 100755 --- a/services/param/trigger/trigger_manager.c +++ b/services/param/trigger/trigger_manager.c @@ -410,8 +410,7 @@ static int CheckParamMatch_(const TriggerWorkSpace *workSpace, PARAM_CHECK((type == TRIGGER_PARAM) || (type == TRIGGER_PARAM_WAIT), return -1, "Invaid type"); CalculatorInit(calculator, MAX_CONDITION_NUMBER, sizeof(LogicData), 1); - int ret = GetValueFromContent(content, contentSize, - 0, calculator->inputName, SUPPORT_DATA_BUFFER_MAX); + int ret = GetValueFromContent(content, contentSize, 0, calculator->inputName, SUPPORT_DATA_BUFFER_MAX); PARAM_CHECK(ret == 0, return -1, "Failed parse content name"); ret = GetValueFromContent(content, contentSize, strlen(calculator->inputName) + 1, calculator->inputContent, SUPPORT_DATA_BUFFER_MAX); @@ -727,7 +726,7 @@ int CheckWatchTriggerTimeout(void) TriggerHeader *GetTriggerHeader(const TriggerWorkSpace *workSpace, int type) { - if (workSpace== NULL || type >= TRIGGER_MAX) { + if (workSpace == NULL || type >= TRIGGER_MAX) { return NULL; } return (TriggerHeader *)&workSpace->triggerHead[type]; diff --git a/test/plugintest/plugin_param_test.c b/test/plugintest/plugin_param_test.c index fa689192..7af37286 100755 --- a/test/plugintest/plugin_param_test.c +++ b/test/plugintest/plugin_param_test.c @@ -17,7 +17,6 @@ #include #include "plugin_test.h" -#include "init_param.h" #include "init_plugin.h" #define MAX_COUNT 1000 -- GitLab