Skip to content

Commit

Permalink
[Tests/unit/core] : fix out of bounds and value tests for 'test_cycli…
Browse files Browse the repository at this point in the history
…cbuffer'
  • Loading branch information
msieben committed Aug 21, 2024
1 parent c198470 commit ebdad80
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Tests/unit/core/test_cyclicbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,10 @@ namespace Core {
uint16_t size;
EXPECT_EQ(buffer.Read(reinterpret_cast<uint8_t*>(&size), 2), 2);

uint8_t loadBuffer[cyclicBufferSize + 1];
uint8_t loadBuffer[size + 1];

ASSERT_GE(size, 2);

uint32_t result = buffer.Read(loadBuffer, size - 2);
loadBuffer[result] = '\0';
EXPECT_EQ(result, size - 2);
Expand All @@ -1385,10 +1388,10 @@ namespace Core {
EXPECT_EQ(result, size);

result = buffer.Write(reinterpret_cast<const uint8_t*>(&size), 2);
EXPECT_EQ(result, size);
EXPECT_EQ(result, 2);

result = buffer.Write(reinterpret_cast<const uint8_t*>(data.c_str()), 1);
EXPECT_EQ(result, size);
EXPECT_EQ(result, 1);

data = "lmnopq";
result = buffer.Write(reinterpret_cast<const uint8_t*>(data.c_str()), 6);
Expand All @@ -1402,10 +1405,10 @@ namespace Core {
EXPECT_EQ(result, size);

result = buffer.Write(reinterpret_cast<const uint8_t*>(&size), 2);
EXPECT_EQ(result, size);
EXPECT_EQ(result, 2);

result = buffer.Write(reinterpret_cast<const uint8_t*>(data.c_str()), size - 2);
EXPECT_EQ(result, size);
EXPECT_EQ(result, size - 2);

EXPECT_EQ(buffer.Free(), 3u);
EXPECT_EQ(buffer.Used(), 7u);
Expand Down

0 comments on commit ebdad80

Please sign in to comment.