Skip to content

Commit 371fba8

Browse files
authored
Bugfix: clear map before deserializing with string as values in XCRv1 (#233)
* Refs #21443: Add regression test Signed-off-by: Mario Dominguez <[email protected]> * Refs #21443: Add fix Signed-off-by: Mario Dominguez <[email protected]> * Refs #21556: Apply Ricardo's suggestion Signed-off-by: Mario Dominguez <[email protected]> --------- Signed-off-by: Mario Dominguez <[email protected]>
1 parent e17fdc4 commit 371fba8

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

include/fastcdr/Cdr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,8 @@ class Cdr
20242024

20252025
deserialize(sequence_length);
20262026

2027+
map_t.clear();
2028+
20272029
try
20282030
{
20292031
for (uint32_t i = 0; i < sequence_length; ++i)

test/cdr/SimpleTest.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,6 +2251,35 @@ TEST(CDRTests, Complete)
22512251
free(c_wstring_value);
22522252
}
22532253

2254+
// Regression test for Fast DDS issue #5136
2255+
// A non-empty map should be cleared before deserializing in XCDRv1
2256+
TEST(CDRTests, DeserializeIntoANonEmptyMapInXCDRv1)
2257+
{
2258+
char buffer[14] =
2259+
{
2260+
0x00, 0x00, 0x00, 0x01, // Map length
2261+
0x00, 0x02, // Key
2262+
0x00, 0x00, // Alignment
2263+
0x00, 0x00, 0x00, 0x01, // Length
2264+
65, 0x00 // 'A'
2265+
};
2266+
2267+
std::map<uint16_t, std::string> initialized_map{
2268+
{1, "a"}
2269+
};
2270+
2271+
FastBuffer cdr_buffer(buffer, 14);
2272+
Cdr cdr_ser_map(
2273+
cdr_buffer,
2274+
eprosima::fastcdr::Cdr::Endianness::BIG_ENDIANNESS,
2275+
XCDRv1);
2276+
2277+
// Deserialization in a non-empty map
2278+
cdr_ser_map >> initialized_map;
2279+
ASSERT_EQ(initialized_map.size(), 1u);
2280+
ASSERT_EQ(initialized_map.at(2), "A");
2281+
}
2282+
22542283
TEST(FastCDRTests, Octet)
22552284
{
22562285
// Check good case.

0 commit comments

Comments
 (0)