Skip to content

Commit

Permalink
Fixing SequenceNumberSet_t deserialization (#2079) (#2906)
Browse files Browse the repository at this point in the history
* [12168] fixing SequenceNumberSet_t deserialization

* [12168] test SequenceNumberSet_t deserialization

(cherry picked from commit d12789c)

Co-authored-by: MiguelBarro <45819833+MiguelBarro@users.noreply.github.com>
  • Loading branch information
mergify[bot] and MiguelBarro authored Aug 9, 2022
1 parent a00453f commit 948fecb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/fastrtps/utils/fixed_size_bitmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,11 @@ class BitmapRange
uint32_t num_bytes = num_items * static_cast<uint32_t>(sizeof(uint32_t));
bitmap_.fill(0u);
memcpy(bitmap_.data(), bitmap, num_bytes);
if (0 < num_bits)
// trim unused bits if (0 < num_bits && num_bits % 32 != 0)
short shift = num_bits & 31u;
if (0 < num_bits && shift != 0)
{
bitmap_[num_items - 1] &= ~(std::numeric_limits<uint32_t>::max() >> (num_bits & 31u));
bitmap_[num_items - 1] &= ~(std::numeric_limits<uint32_t>::max() >> shift);
}
calc_maximum_bit_set(num_items, 0);
}
Expand Down
21 changes: 21 additions & 0 deletions test/unittest/utils/BitmapRangeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ TEST_F(BitmapRangeTests, full_range)

TEST_F(BitmapRangeTests, serialization)
{
using value_type = TestType::bitmap_type::value_type;

uint32_t num_bits;
uint32_t num_longs;
TestType::bitmap_type bitmap;
Expand All @@ -455,6 +457,25 @@ TEST_F(BitmapRangeTests, serialization)
EXPECT_EQ(num_bits, 20u);
EXPECT_EQ(num_longs, 1u);
EXPECT_EQ(bitmap[0], 0xFFFFF000u);

// Case when whole bitmap elements are used
uint32_t test_longs = 1;

do
{
uint32_t test_bits = test_longs * sizeof(value_type) * 8;
bitmap.fill(std::numeric_limits<uint32_t>::max());
uut.bitmap_set(test_bits, bitmap.data());
uut.bitmap_get(num_bits, bitmap, num_longs);
EXPECT_EQ(num_bits, test_bits);
EXPECT_EQ(num_longs, test_longs);

// use a vector as result pattern
std::vector<value_type> pattern(test_longs, std::numeric_limits<uint32_t>::max());
pattern.resize(bitmap.max_size(), 0);
EXPECT_TRUE(std::equal(bitmap.begin(), bitmap.end(), pattern.begin()));
}
while ( ++test_longs <= bitmap.max_size());
}

TEST_F(BitmapRangeTests, traversal)
Expand Down

0 comments on commit 948fecb

Please sign in to comment.