fix(test): fix the heap-buffer-overflow bug and bad/invalid test cases.
(1)Fix bad and invalid test cases.
(2)Add a test case for boundary 0.
(3)Fix the heap-after-free bug.
diff --git a/test/src/common/MemoryBlockTest.cpp b/test/src/common/MemoryBlockTest.cpp
index bfd7b92..4b72d6c 100644
--- a/test/src/common/MemoryBlockTest.cpp
+++ b/test/src/common/MemoryBlockTest.cpp
@@ -48,8 +48,8 @@
char* buf = (char*)malloc(sizeof(char) * 9);
strcpy(buf, "RocketMQ");
- MemoryBlock fiveMemoryBlock(buf, -1);
- EXPECT_EQ(fiveMemoryBlock.getSize(), -1);
+ MemoryBlock fiveMemoryBlock(buf, 0);
+ EXPECT_EQ(fiveMemoryBlock.getSize(), 0);
EXPECT_TRUE(fiveMemoryBlock.getData() == nullptr);
char* bufNull = NULL;
@@ -57,6 +57,7 @@
EXPECT_EQ(sixMemoryBlock.getSize(), 16);
EXPECT_TRUE(sixMemoryBlock.getData() != nullptr);
+ buf = (char*)realloc(buf, 20);
MemoryBlock sevenMemoryBlock(buf, 20);
EXPECT_EQ(sevenMemoryBlock.getSize(), 20);
sevenMemoryBlock.getData();