File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -743,12 +743,19 @@ void MqttClient::message_arrived(mqtt::const_message_ptr mqtt_msg) {
743
743
char * non_const_payload = const_cast <char *>(&payload[0 ]);
744
744
uint8_t * msg_type_buffer = reinterpret_cast <uint8_t *>(non_const_payload);
745
745
746
- // TODO: might crash if payload by chance does not contain ros msg type
747
746
// deserialize ROS message type
748
747
RosMsgType ros_msg_type;
749
748
ros::serialization::IStream msg_type_stream (msg_type_buffer,
750
749
payload_length);
751
- ros::serialization::deserialize (msg_type_stream, ros_msg_type);
750
+ try {
751
+ ros::serialization::deserialize (msg_type_stream, ros_msg_type);
752
+ } catch (ros::serialization::StreamOverrunException) {
753
+ NODELET_ERROR (
754
+ " Failed to deserialize ROS message type from MQTT message received on "
755
+ " topic '%s', got message:\n %s" ,
756
+ mqtt_topic.c_str (), mqtt_msg->to_string ().c_str ());
757
+ return ;
758
+ }
752
759
753
760
// reconstruct corresponding MQTT data topic
754
761
std::string mqtt_data_topic = mqtt_topic;
You can’t perform that action at this time.
0 commit comments