From 0cb17e58767abab30d350d1c8fad383dba2d50e9 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Sat, 16 Oct 2021 06:47:31 +0200 Subject: [PATCH] Fix ReadFromBuffer() for empty strings in Debug mode with assertions enabled --- include/ros_msg_parser/helper_functions.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/ros_msg_parser/helper_functions.hpp b/include/ros_msg_parser/helper_functions.hpp index e5e023e..e6a33dc 100644 --- a/include/ros_msg_parser/helper_functions.hpp +++ b/include/ros_msg_parser/helper_functions.hpp @@ -97,6 +97,11 @@ template <> inline void ReadFromBuffer( const Span& buffer, size_ throw std::runtime_error("Buffer overrun in RosMsgParser::ReadFromBuffer"); } + if (string_size == 0) { + destination = std::string(); + return; + } + const char* buffer_ptr = reinterpret_cast( &buffer[offset] ); offset += string_size;