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

Fix compiler warning in SerialManagerBase.cpp #61

Closed
wants to merge 1 commit into from

Conversation

jamescookmd
Copy link

@jamescookmd jamescookmd commented Dec 23, 2021

When I compile the first example (AudioPassThru) I get this warning:
/Users/jamescook/Documents/Arduino/libraries/Tympan_Library/src/SerialManagerBase.cpp: In member function 'virtual void SerialManagerBase::respondToByte(char)':
/Users/jamescook/Documents/Arduino/libraries/Tympan_Library/src/SerialManagerBase.cpp:56:46: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
stream_length = ((int)(stream_data));

The warning comes from the cast of byte stream_data[SIZE] to int*. See
https://www.ibm.com/docs/en/ztpf/1.1.0.14?topic=warnings-type-pun-problems

Since the code appears to be correct, use reinterpret_cast<> and a
separate local variable to avoid the warning.

This is my first github pull request, please let me know if I'm doing something wrong. :-)

When I compile the first example (AudioPassThru) I get this warning:
/Users/jamescook/Documents/Arduino/libraries/Tympan_Library/src/SerialManagerBase.cpp: In member function 'virtual void SerialManagerBase::respondToByte(char)':
/Users/jamescook/Documents/Arduino/libraries/Tympan_Library/src/SerialManagerBase.cpp:56:46: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         stream_length = *((int*)(stream_data));

The warning comes from the cast of byte stream_data[SIZE] to int*. See
https://www.ibm.com/docs/en/ztpf/1.1.0.14?topic=warnings-type-pun-problems

Since the code appears to be correct, use reinterpret_cast<> and a
separate local variable to avoid the warning.
@jamescookmd jamescookmd marked this pull request as ready for review December 23, 2021 14:48
@jamescookmd
Copy link
Author

@chipaudette please take a look. (And let me know if I'm doing the code review workflow wrong -- this is my first pull request!)

@eyuan-creare
Copy link
Contributor

eyuan-creare commented Jun 14, 2022

Hello @jamescookmd. Thanks for creating this pull request and bringing the issue to our attention. I found myself needing to extend the datastream capabilities so I added a way to set a callback when a multi-byte data stream message is received. I addressed the de-referenced type pun warning by using memcpy to avoid memory misalignment errors. I hope that you find it satisfactory. If not, please raise a concern at the new pull request.

Because this new pull request covers this issue as well, I am closing it. Thanks for your contributions!
Feature_Add_Callback_for_Datastream_Messages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants