Skip to content

Commit ddc8a9c

Browse files
authored
Fix uninitialized memory in test (#2498)
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]>
1 parent dd81ef2 commit ddc8a9c

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

rclcpp/test/rclcpp/test_publisher_with_type_adapter.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,7 @@ TEST_F(TestPublisher, test_large_message_unique)
379379
auto pub = node->create_publisher<StringTypeAdapter>(topic_name, 1);
380380

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

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

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

0 commit comments

Comments
 (0)