Skip to content

Commit

Permalink
Bugfix: clear map before deserializing with string as values in XCRv1 (
Browse files Browse the repository at this point in the history
…#233)

* Refs #21443: Add regression test

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>

* Refs #21443: Add fix

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>

* Refs #21556: Apply Ricardo's suggestion

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>

---------

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
  • Loading branch information
Mario-DL authored Sep 10, 2024
1 parent e17fdc4 commit 371fba8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/fastcdr/Cdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,8 @@ class Cdr

deserialize(sequence_length);

map_t.clear();

try
{
for (uint32_t i = 0; i < sequence_length; ++i)
Expand Down
29 changes: 29 additions & 0 deletions test/cdr/SimpleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,35 @@ TEST(CDRTests, Complete)
free(c_wstring_value);
}

// Regression test for Fast DDS issue #5136
// A non-empty map should be cleared before deserializing in XCDRv1
TEST(CDRTests, DeserializeIntoANonEmptyMapInXCDRv1)
{
char buffer[14] =
{
0x00, 0x00, 0x00, 0x01, // Map length
0x00, 0x02, // Key
0x00, 0x00, // Alignment
0x00, 0x00, 0x00, 0x01, // Length
65, 0x00 // 'A'
};

std::map<uint16_t, std::string> initialized_map{
{1, "a"}
};

FastBuffer cdr_buffer(buffer, 14);
Cdr cdr_ser_map(
cdr_buffer,
eprosima::fastcdr::Cdr::Endianness::BIG_ENDIANNESS,
XCDRv1);

// Deserialization in a non-empty map
cdr_ser_map >> initialized_map;
ASSERT_EQ(initialized_map.size(), 1u);
ASSERT_EQ(initialized_map.at(2), "A");
}

TEST(FastCDRTests, Octet)
{
// Check good case.
Expand Down

0 comments on commit 371fba8

Please sign in to comment.