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

!632 Fix:内源代码检视用例问题

Merge pull request !632 from xuxinyu/Fixmem
...@@ -46,6 +46,7 @@ extern int g_iteration; ...@@ -46,6 +46,7 @@ extern int g_iteration;
void ReallocFuzzTest(void) void ReallocFuzzTest(void)
{ {
char *source = NULL; char *source = NULL;
char *buf = NULL;
int c; int c;
printf("Fuzz test in line [%d] realloc start\n", __LINE__); printf("Fuzz test in line [%d] realloc start\n", __LINE__);
...@@ -59,6 +60,7 @@ void ReallocFuzzTest(void) ...@@ -59,6 +60,7 @@ void ReallocFuzzTest(void)
INIT_FuzzEnvironment(); INIT_FuzzEnvironment();
CreatPrecondForQueue(); CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
source = buf;
hi_watchdog_feed(); hi_watchdog_feed();
heartbeatPrint(i); heartbeatPrint(i);
...@@ -66,10 +68,13 @@ void ReallocFuzzTest(void) ...@@ -66,10 +68,13 @@ void ReallocFuzzTest(void)
if ((c <= 0) || (c > TEST_MAX_BUF_LEN)) { if ((c <= 0) || (c > TEST_MAX_BUF_LEN)) {
c = TEST_BUF_LEN; c = TEST_BUF_LEN;
} }
source = (char *)realloc(source, c); buf = (char *)realloc(source, c);
if (buf == NULL) {
break;
}
} }
if (source == NULL) { if (buf == NULL) {
free(source); free(source);
} }
......
...@@ -270,19 +270,22 @@ LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemRealloc001, Function | MediumTest ...@@ -270,19 +270,22 @@ LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemRealloc001, Function | MediumTest
memset(mem, testChar, mlen); memset(mem, testChar, mlen);
rlen = rand() % (1024) + mlen; rlen = rand() % (1024) + mlen;
mem = realloc(mem, rlen); char *mem1 = realloc(mem, rlen);
TEST_ASSERT_NOT_NULL(mem); if (mem1 == NULL) {
free(mem);
}
TEST_ASSERT_NOT_NULL(mem1);
len = mlen <= rlen ? mlen : rlen; len = mlen <= rlen ? mlen : rlen;
data = (char *)mem; data = (char *)mem1;
for (k = 0; k < len; k++) { for (k = 0; k < len; k++) {
if (data[k] != testChar) { if (data[k] != testChar) {
failure = 1; failure = 1;
} }
} }
free(mem); free(mem1);
TEST_ASSERT_EQUAL_INT(failure, 0); TEST_ASSERT_EQUAL_INT(failure, 0);
} }
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册