Skip to content

[21556] Bugfix: clear map before deserializing with string as values in XCRv1 #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading