From 543732f5229a20a7fdeb82d6336919b85e47f1a8 Mon Sep 17 00:00:00 2001 From: x_xiny <1301913191@qq.com> Date: Mon, 14 Mar 2022 21:03:26 +0800 Subject: [PATCH] =?UTF-8?q?=20fix:=E6=A0=B9=E6=8D=AE=E5=86=85=E6=BA=90?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81=E5=AF=B9?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E8=BF=9B=E8=A1=8C=E6=95=B4=E6=94=B9=20=20=20?= =?UTF-8?q?=20=20=E3=80=90=E8=83=8C=E6=99=AF=E3=80=913.1=E4=BB=A3=E7=A0=81?= =?UTF-8?q?review=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【修改方案】 修复用例问题 Signed-off-by: xuiny Change-Id: I8ee5d8f5f5765e469cf72c810af8a3831a3879f9 --- testsuites/unittest/fuzz/src/stdlib/realloc_fuzz.c | 9 +++++++-- .../unittest/posix/src/string/memory_func_test.c | 11 +++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/testsuites/unittest/fuzz/src/stdlib/realloc_fuzz.c b/testsuites/unittest/fuzz/src/stdlib/realloc_fuzz.c index 96a6d97e..eebda93e 100644 --- a/testsuites/unittest/fuzz/src/stdlib/realloc_fuzz.c +++ b/testsuites/unittest/fuzz/src/stdlib/realloc_fuzz.c @@ -46,6 +46,7 @@ extern int g_iteration; void ReallocFuzzTest(void) { char *source = NULL; + char *buf = NULL; int c; printf("Fuzz test in line [%d] realloc start\n", __LINE__); @@ -59,6 +60,7 @@ void ReallocFuzzTest(void) INIT_FuzzEnvironment(); CreatPrecondForQueue(); for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) { + source = buf; hi_watchdog_feed(); heartbeatPrint(i); @@ -66,10 +68,13 @@ void ReallocFuzzTest(void) if ((c <= 0) || (c > TEST_MAX_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); } diff --git a/testsuites/unittest/posix/src/string/memory_func_test.c b/testsuites/unittest/posix/src/string/memory_func_test.c index 6faf65f7..6b553131 100644 --- a/testsuites/unittest/posix/src/string/memory_func_test.c +++ b/testsuites/unittest/posix/src/string/memory_func_test.c @@ -270,19 +270,22 @@ LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemRealloc001, Function | MediumTest memset(mem, testChar, mlen); rlen = rand() % (1024) + mlen; - mem = realloc(mem, rlen); - TEST_ASSERT_NOT_NULL(mem); + char *mem1 = realloc(mem, rlen); + if (mem1 == NULL) { + free(mem); + } + TEST_ASSERT_NOT_NULL(mem1); len = mlen <= rlen ? mlen : rlen; - data = (char *)mem; + data = (char *)mem1; for (k = 0; k < len; k++) { if (data[k] != testChar) { failure = 1; } } - free(mem); + free(mem1); TEST_ASSERT_EQUAL_INT(failure, 0); } };