ros / roscpp_core

ros distribution sandbox
88 stars 116 forks source link

Issues with misaligned pointers in serialization #76

Closed poggenhans closed 6 years ago

poggenhans commented 6 years ago

Is there a reason why ROS uses reinterpret_cast instead of memcpy for serializing on x86? When I compile any node with GCC's undefined behaviour sanitizer, I get a bunch of errors like the following:

/opt/ros/kinetic/include/ros/serialization.h:234:129: runtime error: store to misaligned address 0x619000006e9f for type 'double', which requires 8 byte alignment
0x619000006e9f: note: pointer points here
 69 63 6c 65 be  be be be be be be be be  be be be be be be be be  be be be be be be be be  be be be
             ^ 
/opt/ros/kinetic/include/ros/serialization.h:234:269: runtime error: load of misaligned address 0x7f462000461b for type 'double', which requires 8 byte alignment
0x7f462000461b: note: pointer points here
 69  63 6c 65 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00
cwecht commented 6 years ago

This can be reproduced by calling e.g. this:

catkin_make -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS_DEBUG="-fsanitize=alignment -fuse-ld=gold" tests run_tests_test_roscpp_rostest_test_launch_subscribe_self.xml

using a workspace containing ros_comm.