diff --git a/kernel_lite/io_posix/src/IoTestStdio.cpp b/kernel_lite/io_posix/src/IoTestStdio.cpp index c22a6eb508d12b10e5d205be2b621f3437efec94..b1bfb8916ee1237ee547d1f478e0d9505389df5c 100755 --- a/kernel_lite/io_posix/src/IoTestStdio.cpp +++ b/kernel_lite/io_posix/src/IoTestStdio.cpp @@ -334,6 +334,7 @@ HWTEST_F(IoTest, testVasprintf, Function | MediumTest | Level1) ret = FormatVasprintf(&buf, "%f and %c as well as %ld\n", 2.2, 'c', 6); EXPECT_EQ(ret, 28); EXPECT_STREQ(buf, "2.200000 and c as well as 6\n"); + free(buf); } /** diff --git a/kernel_lite/mem_posix/src/ActsMemApiTest.cpp b/kernel_lite/mem_posix/src/ActsMemApiTest.cpp index 122c6b855dae63c782dd112f26b8f3eec2f69375..8e2b0c09414e1f50dbf104e428883928ba404b86 100755 --- a/kernel_lite/mem_posix/src/ActsMemApiTest.cpp +++ b/kernel_lite/mem_posix/src/ActsMemApiTest.cpp @@ -297,8 +297,10 @@ HWTEST_F(ActsMemApiTest, testMemmem_0100, Function | MediumTest | Level1) { LogPrint(" memmem *haystack:='%s' size_haystack:='%d' ", srcStr, strlen(srcStr)); LogPrint("*needle:='%s' size_needle:='%d',\n", srcSubStr, strlen(srcSubStr)); + if (strlen(srcStr) >= strlen(srcSubStr)) { pos = (char *)memmem(srcStr, strlen(srcStr), srcSubStr, strlen(srcSubStr)); LogPrint(" --> return pos:='%x'\n", pos); + } ASSERT_TRUE(pos) << "ErrInfo: memmem *haystack:='" << srcStr << " size_haystack:='" @@ -315,7 +317,10 @@ HWTEST_F(ActsMemApiTest, testMemmem_1000, Function | MediumTest | Level1) { char srcStr[] = "this is str a;"; char srcSubStr[] = "strb"; char *pos = nullptr; - + + if (strlen(srcStr) < strlen(srcSubStr)) { + FAIL(); + } pos = (char *)memmem(srcStr, strlen(srcStr), srcSubStr, strlen(srcSubStr)); LogPrint(" memmem *haystack:='%s' size_haystack:='%d' ", srcStr, strlen(srcStr)); LogPrint("*needle:='%s' size_needle:='%d',\n", srcSubStr, strlen(srcSubStr)); diff --git a/kernel_lite/net_posix/src/ActsNetTest.cpp b/kernel_lite/net_posix/src/ActsNetTest.cpp index edbf4fd12b62a9d1c866dca8ce332f764c891c20..7ed18c837be4ecc289ed62efde7cd3098299c76a 100755 --- a/kernel_lite/net_posix/src/ActsNetTest.cpp +++ b/kernel_lite/net_posix/src/ActsNetTest.cpp @@ -236,7 +236,7 @@ static void* SampleTcpServerTask(void *p) WAIT(); static char bufrec[BUF_SIZE + 1] = {0}; - memset_s(bufrec, BUF_SIZE, 0, BUF_SIZE); + memset_s(bufrec, sizeof(bufrec), 0, BUF_SIZE); memset_s(&msg, sizeof(msg), 0, sizeof(msg)); msg.msg_name = &clnAddr; msg.msg_namelen = sizeof(clnAddr); @@ -331,7 +331,7 @@ static void* SampleTcpClientTask(void *p) WAIT(); static char bufrec[BUF_SIZE + 1] = {0}; - memset_s(bufrec, BUF_SIZE, 0, BUF_SIZE); + memset_s(bufrec, sizeof(bufrec), 0, BUF_SIZE); memset_s(&msg, sizeof(msg), 0, sizeof(msg)); msg.msg_name = &clnAddr; msg.msg_namelen = sizeof(clnAddr); @@ -340,7 +340,7 @@ static void* SampleTcpClientTask(void *p) iov[0].iov_base = bufrec; iov[0].iov_len = sizeof(bufrec); ret = recvmsg(clnFd, &msg, 0); - if (len * strlen(g_srvMsg) == (unsigned int)ret) { + if (len * strlen(g_srvMsg) == (unsigned int)ret && ret >= 0) { bufrec[ret] = 0; printf("[tcp client]recvmsg, ret=%d, msg[%s]\n", ret, bufrec); } else {