Skip to content

Commit

Permalink
Fix uninitialized memory in test (#2498)
Browse files Browse the repository at this point in the history
When I added in the tests for large messages, I made a mistake and reserved space in the strings, but didn't actually expand it.  Thus, we were writing into uninitialized memory.  Fix this by just using the correct constructor for string, which will allocate and initialize the memory properly.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette authored Apr 11, 2024
1 parent dd81ef2 commit ddc8a9c
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions rclcpp/test/rclcpp/test_publisher_with_type_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,7 @@ TEST_F(TestPublisher, test_large_message_unique)
auto pub = node->create_publisher<StringTypeAdapter>(topic_name, 1);

static constexpr size_t length = 10 * 1024 * 1024;
auto message_data = std::make_unique<std::string>();
message_data->reserve(length);
std::fill(message_data->begin(), message_data->begin() + length, '#');
auto message_data = std::make_unique<std::string>(length, '#');
pub->publish(std::move(message_data));
}

Expand All @@ -400,8 +398,6 @@ TEST_F(TestPublisher, test_large_message_constref)
auto pub = node->create_publisher<StringTypeAdapter>(topic_name, 1);

static constexpr size_t length = 10 * 1024 * 1024;
std::string message_data;
message_data.reserve(length);
std::fill(message_data.begin(), message_data.begin() + length, '#');
std::string message_data(length, '#');
pub->publish(message_data);
}

0 comments on commit ddc8a9c

Please sign in to comment.