Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about handling of array messages #219

Closed
anhosi opened this issue Jul 26, 2018 · 7 comments
Closed

Question about handling of array messages #219

anhosi opened this issue Jul 26, 2018 · 7 comments
Labels
bug Something isn't working

Comments

@anhosi
Copy link

anhosi commented Jul 26, 2018

I am not sure whether this is the correct place for this issue. So please direct me to a better location.

Together with @Karsten1987 we stumbled over

auto vector = reinterpret_cast<std::vector<unsigned char> *>(field);
.

I have only limited understanding about the whole rmw. As far as I understand a array message member that is originally represented as a std::vector<T> * is reinterpret_casted to a std::vector<unsigned char> * with a void * as intermediate. IMHO this is not guaranteed to work by the C++ standard as implementations are allowed to use different template specializations of std::vector for different types. There are only guarantees for the memory layout of a vectors data().
As far as I can tell the above code is only the symptom as the void * field here is part of what is passed into rmw_serialize as ros_message. Maybe it would be better to pass only the data() pointer of the vector at some point instead of the whole vector as void *?

@deeplearningrobotics
Copy link

IMHO, if field was not originally cast to void * from a std::vector<unsigned char> * then this code yields undefined behavior according to the type aliasing rules.

https://en.cppreference.com/w/cpp/language/reinterpret_cast -> Type aliasing

@anhosi
Copy link
Author

anhosi commented Jul 27, 2018

@deeplearningrobotics exactly. From my understanding field might very well have been a std::vector<float> for a float32[] message member.

@sloretz
Copy link
Contributor

sloretz commented Aug 9, 2018

@richiprosima may I ask you to look at what it would take to fix this?

@deeplearningrobotics
Copy link

@richiware: Could you take a look a this?

Or is this covered under the standard?

Chapter 3.10 (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf )

@richiware
Copy link
Contributor

richiware commented Nov 29, 2018 via email

@deeplearningrobotics
Copy link

@richiware: There are a lot of reinterpret_casts and also casts to and from void * which are undocumented. So I think there is a generally bigger work packages to verify their correctness and somehow document that those do not exhibit UB.

@ivanpauno
Copy link
Member

Closing in favor of #428.
#429 is fixing this.

@ivanpauno ivanpauno added the bug Something isn't working label Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants