未验证 提交 2e4db6ee 编写于 作者: O openharmony_ci 提交者: Gitee

!1109 修复代码静态检查(0822)

Merge pull request !1109 from cheng_jinsong/codex
......@@ -316,7 +316,10 @@ static int GetSlotInfoFromMisc(off_t offset, off_t size)
char miscDev[MAX_BUFFER_LEN] = {0};
BEGET_ERROR_CHECK(GetBlockDevicePath("/misc", miscDev, MAX_BUFFER_LEN) == 0,
return -1, "Failed to get misc device");
int fd = open(miscDev, O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
char *realPath = GetRealPath(miscDev);
BEGET_ERROR_CHECK(realPath != NULL, return -1, "Failed to get misc device real path");
int fd = open(realPath, O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
free(realPath);
BEGET_ERROR_CHECK(fd >= 0, return -1, "Failed to open misc device, errno %d", errno);
BEGET_ERROR_CHECK(lseek(fd, offset, SEEK_SET) >= 0, close(fd); return -1,
"Failed to lseek misc device fd, errno %d", errno);
......
......@@ -69,50 +69,48 @@ def GetParamFromCCode(codeName):
def WriteMapToCode(codeName, dict):
try:
f = open(codeName, 'w')
# start with 0
f.seek(0)
# write file header
f.write('#ifndef PARAM_LITE_DEF_CFG_' + os.linesep)
f.write('#define PARAM_LITE_DEF_CFG_' + os.linesep)
f.write('#include <stdint.h>' + os.linesep + os.linesep)
f.write('#ifdef __cplusplus' + os.linesep)
f.write('#if __cplusplus' + os.linesep)
f.write('extern "C" {' + os.linesep)
f.write('#endif' + os.linesep)
f.write('#endif' + os.linesep + os.linesep)
#define struct
f.write('typedef struct Node_ {' + os.linesep)
f.write(' const char *name;' + os.linesep)
f.write(' const char *value;' + os.linesep)
f.write('} Node;' + os.linesep + os.linesep)
f.write('#define PARAM_MAP(name, value) {(const char *)#name, (const char *)#value},')
f.write(os.linesep + os.linesep)
# write data
f.write('static Node g_paramDefCfgNodes[] = {' + os.linesep)
for name, value in dict.items():
if (value.startswith("\"")):
str = " PARAM_MAP({0}, {1})".format(name, value)
f.write(str + os.linesep)
else:
str = " PARAM_MAP({0}, \"{1}\")".format(name, value)
f.write(str + os.linesep)
f.write('};' + os.linesep + os.linesep)
#end
f.write('#ifdef __cplusplus' + os.linesep)
f.write('#if __cplusplus' + os.linesep)
f.write('}' + os.linesep)
f.write('#endif' + os.linesep)
f.write('#endif' + os.linesep)
f.write('#endif // PARAM_LITE_DEF_CFG_' + os.linesep)
f.write(os.linesep)
f.truncate()
with open(codeName, "w") as f:
# start with 0
f.seek(0)
# write file header
f.write('#ifndef PARAM_LITE_DEF_CFG_' + os.linesep)
f.write('#define PARAM_LITE_DEF_CFG_' + os.linesep)
f.write('#include <stdint.h>' + os.linesep + os.linesep)
f.write('#ifdef __cplusplus' + os.linesep)
f.write('#if __cplusplus' + os.linesep)
f.write('extern "C" {' + os.linesep)
f.write('#endif' + os.linesep)
f.write('#endif' + os.linesep + os.linesep)
#define struct
f.write('typedef struct Node_ {' + os.linesep)
f.write(' const char *name;' + os.linesep)
f.write(' const char *value;' + os.linesep)
f.write('} Node;' + os.linesep + os.linesep)
f.write('#define PARAM_MAP(name, value) {(const char *)#name, (const char *)#value},')
f.write(os.linesep + os.linesep)
# write data
f.write('static Node g_paramDefCfgNodes[] = {' + os.linesep)
for name, value in dict.items():
if (value.startswith("\"")):
str = " PARAM_MAP({0}, {1})".format(name, value)
f.write(str + os.linesep)
else:
str = " PARAM_MAP({0}, \"{1}\")".format(name, value)
f.write(str + os.linesep)
f.write('};' + os.linesep + os.linesep)
#end
f.write('#ifdef __cplusplus' + os.linesep)
f.write('#if __cplusplus' + os.linesep)
f.write('}' + os.linesep)
f.write('#endif' + os.linesep)
f.write('#endif' + os.linesep)
f.write('#endif // PARAM_LITE_DEF_CFG_' + os.linesep)
f.write(os.linesep)
f.truncate()
except IOError:
print("Error: open or write file %s fail"%{codeName})
else:
f.close()
return 0
def AddToCodeDict(codeDict, cfgDict, high = True):
......@@ -142,14 +140,14 @@ def main():
out_dir = args.dest_dir
if not os.path.exists(out_dir):
os.makedirs(out_dir, exist_ok=True)
print("out_dir " + out_dir)
print("out_dir {}".format(out_dir))
for source in args.source:
print("source " + source)
print("source {}".format(out_dir))
assert os.path.exists(source)
srcDict = GetParamFromCfg(source)
dst = out_dir + "param_cfg.h"
dst = "".join([out_dir, "param_cfg.h"])
if os.path.exists(dst):
dstDict = GetParamFromCCode(dst)
......
......@@ -33,8 +33,9 @@ static int main_cmd(BShellHandle shell, int argc, char **argv)
printf("dump service bootevent info \n");
size_t serviceNameLen = strlen(argv[1]) + strlen(argv[2]) + 2; // 2 is \0 and #
char *serviceBootevent = (char *)calloc(1, serviceNameLen);
BEGET_ERROR_CHECK(serviceBootevent != NULL, return 0, "failed to allocate bootevent memory");
BEGET_ERROR_CHECK(sprintf_s(serviceBootevent, serviceNameLen, "%s#%s", argv[1], argv[2]) >= 0,
return 0, "dumpservice arg create failed");
free(serviceBootevent); return 0, "dumpservice arg create failed");
CmdClientInit(INIT_CONTROL_FD_SOCKET_PATH, ACTION_DUMP, serviceBootevent);
free(serviceBootevent);
} else {
......
......@@ -19,7 +19,7 @@
#include "v1_0/ipartition_slot.h"
using namespace OHOS::HDI::Partitionslot::V1_0;
const int32_t PARTITION_ARGC = 2;
static const int32_t PARTITION_ARGC = 2;
static int GetSlot(BShellHandle handle, int32_t argc, char *argv[])
{
......
......@@ -67,7 +67,7 @@ def fix_para_file(options):
with open(options.output, 'w') as f:
for key in contents:
f.write(key + "=" + contents[key] + '\n')
f.write("".join([key, "=", contents[key], '\n']))
def main(args):
options = parse_args(args)
......
......@@ -33,7 +33,7 @@ int ConnectServer(int fd, const char *servername)
addr.sun_family = AF_UNIX;
ret = sprintf_s(addr.sun_path, sizeof(addr.sun_path) - 1, "%s", servername);
PARAM_CHECK(ret > EOK, return -1, "Failed to sprintf_s server address");
size_t len = offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path);
socklen_t len = offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path);
ret = connect(fd, (struct sockaddr *)&addr, len);
PARAM_CHECK(ret != -1, return -1, "Failed to connect server %s %d", servername, errno);
PARAM_LOGV("ConnectServer %s success", servername);
......
......@@ -57,7 +57,7 @@ public:
{
pid_t pid = fork();
if (pid == 0) {
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) != 0) {
std::cout << "PR_SET_NO_NEW_PRIVS set fail " << std::endl;
exit(EXIT_FAILURE);
}
......@@ -115,7 +115,7 @@ public:
return -1;
}
if (flag) {
if (flag != 0) {
std::cout << "Child process time out" << std::endl;
}
......
#! /bin/bash
#!/bin/bash
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -16,6 +16,7 @@
# Usage:
# ./prepare_testdata.sh path
# path is the rootdir of ohos projects.
set -e
if [ $# -lt 1 ];then
echo "Usage $0 <product name>"
......@@ -111,7 +112,7 @@ if [ $? -ne 0 ]; then
exit 1
fi
if [ ! -f ${ohos_init}/g.sh ]; then
if [ ! -f "${ohos_init}/g.sh" ]; then
echo "create g.sh"
touch ${ohos_init}/g.sh
echo "${ohos_root}/prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-cov gcov \$@" > ${ohos_init}/g.sh
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册