fix: 内核告警修复
【背景】 经代码扫描工具检测,内核代码中存在 可以修复的告警 【修改方案】 1.将单语句的if, while等加上括号 2.将C语言风格的类型转换变为C++风格 【影响】 对现有的产品编译不会有影响。 Signed-off-by: yinjiaming <yinjiaming@huawei.com> Change-Id: I7d4a04a8904abb3c33e843049bf15f4386d3efd8
This commit is contained in:
@@ -62,20 +62,20 @@ static int LiteIpcTest(void)
|
||||
|
||||
/* testing mmap liteipc mem pool with different size and flag */
|
||||
retptr = mmap(nullptr, 1024 * 4096, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
ICUNIT_ASSERT_EQUAL((int)(intptr_t)retptr, -1, retptr);
|
||||
ICUNIT_ASSERT_EQUAL(static_cast<int>(static_cast<intptr_t>(retptr)), -1, retptr);
|
||||
//retptr = mmap(nullptr, 0, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
//ICUNIT_ASSERT_EQUAL((int)(intptr_t)retptr, -1, retptr);
|
||||
retptr = mmap(nullptr, -1, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
ICUNIT_ASSERT_EQUAL((int)(intptr_t)retptr, -1, retptr);
|
||||
ICUNIT_ASSERT_EQUAL(static_cast<int>(static_cast<intptr_t>(retptr)), -1, retptr);
|
||||
retptr = mmap(nullptr, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
|
||||
ICUNIT_ASSERT_EQUAL((int)(intptr_t)retptr, -1, retptr);
|
||||
ICUNIT_ASSERT_EQUAL(static_cast<int>(static_cast<intptr_t>(retptr)), -1, retptr);
|
||||
retptr = mmap(nullptr, 4096, PROT_READ, MAP_SHARED, fd, 0);
|
||||
ICUNIT_ASSERT_EQUAL((int)(intptr_t)retptr, -1, retptr);
|
||||
ICUNIT_ASSERT_EQUAL(static_cast<int>(static_cast<intptr_t>(retptr)), -1, retptr);
|
||||
|
||||
retptr = mmap(nullptr, 1, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL((int)(intptr_t)retptr, -1, retptr);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(static_cast<int>(static_cast<intptr_t>(retptr)), -1, retptr);
|
||||
retptr = mmap(nullptr, 4095, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
ICUNIT_ASSERT_EQUAL((int)(intptr_t)retptr, -1, retptr);
|
||||
ICUNIT_ASSERT_EQUAL(static_cast<int>(static_cast<intptr_t>(retptr)), -1, retptr);
|
||||
|
||||
/* testing read/write api */
|
||||
char buf[10] = {0};
|
||||
@@ -121,7 +121,7 @@ static int TestCase(void)
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, -1, fd);
|
||||
|
||||
retptr = mmap(nullptr, 16 * 4096, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL((int)(intptr_t)retptr, -1, retptr);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(static_cast<int>(static_cast<intptr_t>(retptr)), -1, retptr);
|
||||
ret = ioctl(fd, IPC_SET_CMS, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
ret = ioctl(fd, IPC_SET_CMS, 200);
|
||||
|
||||
@@ -65,7 +65,7 @@ static int CallTestServiceLoop(uint32_t id)
|
||||
ret = GetService(g_ipcFd, g_serviceName, sizeof(g_serviceName), &serviceHandle);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
retptr = mmap(NULL, 4096, PROT_READ, MAP_PRIVATE, g_ipcFd, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL((int)(intptr_t)retptr, -1, retptr);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(static_cast<int>(static_cast<intptr_t>(retptr)), -1, retptr);
|
||||
ret = GetService(g_ipcFd, g_serviceName, sizeof(g_serviceName), &serviceHandle);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
@@ -141,7 +141,7 @@ static int TestServiceLoop(void)
|
||||
ret = RegService(g_ipcFd, g_serviceName, sizeof(g_serviceName), &serviceHandle);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
retptr = mmap(NULL, 4096, PROT_READ, MAP_PRIVATE, g_ipcFd, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL((int)(intptr_t)retptr, -1, retptr);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(static_cast<int>(static_cast<intptr_t>(retptr)), -1, retptr);
|
||||
ret = RegService(g_ipcFd, g_serviceName, sizeof(g_serviceName), &serviceHandle);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ static UINT32 Testcase(VOID)
|
||||
|
||||
ret = pipe(pipeFd);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);
|
||||
shmid = shmget((key_t)IPC_PRIVATE, sizeof(int), 0666 | IPC_CREAT); // 0666 the authority of the shm
|
||||
shmid = shmget(static_cast<key_t>(IPC_PRIVATE), sizeof(int), 0666 | IPC_CREAT); // 0666 the authority of the shm
|
||||
ICUNIT_ASSERT_NOT_EQUAL(shmid, -1, shmid);
|
||||
sharedflag = (int *)shmat(shmid, NULL, 0);
|
||||
*sharedflag = 0;
|
||||
|
||||
@@ -42,7 +42,7 @@ static UINT32 Testcase(VOID)
|
||||
|
||||
ret = pipe(pipeFd);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);
|
||||
shmid = shmget((key_t)IPC_PRIVATE, sizeof(int), 0666 | IPC_CREAT); // 0666 the authority of the shm
|
||||
shmid = shmget(static_cast<key_t>(IPC_PRIVATE), sizeof(int), 0666 | IPC_CREAT); // 0666 the authority of the shm
|
||||
ICUNIT_ASSERT_NOT_EQUAL(shmid, -1, shmid);
|
||||
sharedflag = (int *)shmat(shmid, NULL, 0);
|
||||
*sharedflag = 0;
|
||||
|
||||
@@ -56,7 +56,7 @@ static int PipecommonWrite()
|
||||
printf("signal error\n");
|
||||
}
|
||||
|
||||
shmid = shmget((key_t)IPC_PRIVATE, sizeof(int), 0666 | IPC_CREAT); // 0666 the authority of the shm
|
||||
shmid = shmget(static_cast<key_t>(IPC_PRIVATE), sizeof(int), 0666 | IPC_CREAT); // 0666 the authority of the shm
|
||||
ICUNIT_ASSERT_NOT_EQUAL(shmid, -1, shmid);
|
||||
sharedflag = (int *)shmat(shmid, NULL, 0);
|
||||
*sharedflag = 0;
|
||||
|
||||
@@ -80,7 +80,7 @@ static UINT32 TestCase(VOID)
|
||||
sigaddset(&newset, SIGCHLD);
|
||||
timeout.tv_nsec = 1;
|
||||
timeout.tv_sec = 3; // 3, set the sec of timeout.
|
||||
ret = sigtimedwait(&newset, (siginfo_t *)2, &timeout); // 2, wait for signal num
|
||||
ret = sigtimedwait(&newset, reinterpret_cast<siginfo_t *>(2), &timeout); // 2, wait for signal num
|
||||
printf("ret = %d errno = %d EFAULT = %d\n", ret, errno, EFAULT);
|
||||
if (ret != -1) {
|
||||
exit(ret);
|
||||
|
||||
@@ -73,7 +73,7 @@ static UINT32 TestCase(VOID)
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
ret = sigsuspend((sigset_t *)2); // 2, suspend signal num.
|
||||
ret = sigsuspend(reinterpret_cast<sigset_t *>(2)); // 2, suspend signal num.
|
||||
if (ret != -1) {
|
||||
exit(ret);
|
||||
}
|
||||
@@ -89,7 +89,7 @@ static UINT32 TestCase(VOID)
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
ret = sigpending((sigset_t *)2); // 2, pending signal num.
|
||||
ret = sigpending(reinterpret_cast<sigset_t *>(2)); // 2, pending signal num.
|
||||
if (ret != -1) {
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ static int TestPipeMultiProcess()
|
||||
|
||||
int flag = fcntl(*readFd, F_GETFL);
|
||||
fcntl(*readFd, F_SETFL, flag | O_NONBLOCK);
|
||||
shmid = shmget((key_t)IPC_PRIVATE, sizeof(int), 0666 | IPC_CREAT); // 0666 the authority of the shm
|
||||
shmid = shmget(static_cast<key_t>(IPC_PRIVATE), sizeof(int), 0666 | IPC_CREAT); // 0666 the authority of the shm
|
||||
ICUNIT_ASSERT_NOT_EQUAL(shmid, -1, shmid);
|
||||
sharedflag = (int *)shmat(shmid, NULL, 0);
|
||||
*sharedflag = 0;
|
||||
|
||||
@@ -47,7 +47,7 @@ static int TestRaiseIgnore(void)
|
||||
|
||||
g_sigCount = 0;
|
||||
// trigger one
|
||||
ret = (void *)signal(sig, SigPrint);
|
||||
ret = reinterpret_cast<void *>(signal(sig, SigPrint));
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, NULL, ret);
|
||||
|
||||
retValue = raise(sig);
|
||||
@@ -55,13 +55,13 @@ static int TestRaiseIgnore(void)
|
||||
|
||||
usleep(1000); // 1000, Used to calculate the delay time.
|
||||
// trigger ignore
|
||||
ret = (void *)signal(sig, SIG_IGN);
|
||||
ret = reinterpret_cast<void *>(signal(sig, SIG_IGN));
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, NULL, ret);
|
||||
|
||||
retValue = raise(sig);
|
||||
ICUNIT_ASSERT_EQUAL(retValue, 0, retValue);
|
||||
// trigger one
|
||||
ret = (void *)signal(sig, SigPrint);
|
||||
ret = reinterpret_cast<void *>(signal(sig, SigPrint));
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, NULL, ret);
|
||||
retValue = raise(sig);
|
||||
ICUNIT_ASSERT_EQUAL(retValue, 0, retValue);
|
||||
|
||||
@@ -63,8 +63,8 @@ static void *ThreadSetFunc2(void *arg)
|
||||
pthread_exit((void *)NULL);
|
||||
return NULL;
|
||||
EXIT:
|
||||
pthread_exit((void *)-1);
|
||||
return (void *)-1;
|
||||
pthread_exit(reinterpret_cast<void *>(-1));
|
||||
return reinterpret_cast<void *>(-1);
|
||||
}
|
||||
|
||||
static void *ThreadSetDfl(void *arg)
|
||||
@@ -76,8 +76,8 @@ static void *ThreadSetDfl(void *arg)
|
||||
pthread_exit((void *)NULL);
|
||||
return NULL;
|
||||
EXIT:
|
||||
pthread_exit((void *)-1);
|
||||
return (void *)-1;
|
||||
pthread_exit(reinterpret_cast<void *>(-1));
|
||||
return reinterpret_cast<void *>(-1);
|
||||
}
|
||||
|
||||
static void *ThreadKill(void *arg)
|
||||
@@ -90,8 +90,8 @@ static void *ThreadKill(void *arg)
|
||||
pthread_exit((void *)NULL);
|
||||
return NULL;
|
||||
EXIT:
|
||||
pthread_exit((void *)-1);
|
||||
return (void *)-1;
|
||||
pthread_exit(reinterpret_cast<void *>(-1));
|
||||
return reinterpret_cast<void *>(-1);
|
||||
}
|
||||
|
||||
static int TestSigMultiPthread(void)
|
||||
@@ -119,15 +119,15 @@ static int TestSigMultiPthread(void)
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
pthread_join(thread, (void **)&status1);
|
||||
pthread_join(thread, reinterpret_cast<void **>(&status1));
|
||||
if ((int)(intptr_t)status1 != 0) {
|
||||
exit(-1);
|
||||
}
|
||||
pthread_join(thread1, (void **)&status1);
|
||||
pthread_join(thread1, reinterpret_cast<void **>(&status1));
|
||||
if ((int)(intptr_t)status1 != 0) {
|
||||
exit(-1);
|
||||
}
|
||||
pthread_join(thread2, (void **)&status1);
|
||||
pthread_join(thread2, reinterpret_cast<void **>(&status1));
|
||||
if ((int)(intptr_t)status1 != 0) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ static UINT32 TestCase(VOID)
|
||||
ICUNIT_ASSERT_EQUAL(retval, -1, retval);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
printf("----------------------------------\n");
|
||||
retval = sigprocmask(SIG_BLOCK, (sigset_t *)1, &oldset);
|
||||
retval = sigprocmask(SIG_BLOCK, reinterpret_cast<sigset_t *>(1), &oldset);
|
||||
ICUNIT_ASSERT_EQUAL(retval, -1, retval);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EFAULT, errno);
|
||||
printf("----------------------------------\n");
|
||||
|
||||
@@ -43,7 +43,7 @@ static UINT32 TestCase(VOID)
|
||||
|
||||
ioctl(fd, TRACE_STOP, NULL);
|
||||
|
||||
buffer= (char *)malloc(size);
|
||||
buffer = (char *)malloc(size);
|
||||
if (buffer == NULL) {
|
||||
printf("Read buffer malloc failed!\n");
|
||||
goto EXIT;
|
||||
|
||||
Reference in New Issue
Block a user