-
Notifications
You must be signed in to change notification settings - Fork 100
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(MiscDrivers): MSDK-1240: Clear out of bounds warnings seen with GCC v13.2 #852
Conversation
ba44aab
to
a435a11
Compare
@@ -926,10 +927,10 @@ int MXC_TFT_Init(void) | |||
memset(&images_header, 0, sizeof(Header_images_t)); | |||
|
|||
// Is there any image data to work with? | |||
if (_bin_start_ != _bin_end_) { | |||
if ((unsigned int *)&_bin_start_ != (unsigned int *)&_bin_end_) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this cast necessary, or should this reference the first field (unsigned int offset2info_palatte) of Header_images_t instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Casting is for readability purposes only. We're checking if any data inserted in this specific block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These casts are the opposite of "readable" and like any cast in C, carry the risk of mis-aligned accesses and access to unallocated memories.
images_start_addr = (unsigned char *)&_bin_start_; | ||
// set header | ||
memcpy(&images_header, images_start_addr, sizeof(Header_images_t)); | ||
images_header = *((Header_images_t *)&_bin_start_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this cast needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GCC 13.2 wants to be informed about the memory address is enough for the related memcopy operation. We're giving a struct type pointer which we claim it will not overflow with the memory copying. Actually *(&_bin_start_) is enough but I added (Header_images_t *) casting for readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not add to readability, it reduces readability and adds the possibility of mis-aligned access, and access to unallocated memories, and incompatible data structures.
This should be
images_header = bin_start;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve casts
5d3bc9f
to
5a42cd3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ahmetalincak
Description
GCC 13.2 warning clearance for tft_ssd2119.c
In the latest compiler version, the array bounds warnings appear. This was an internal issue and I tried building MAX78000 kws20_demo example and saw warnings myself.
The changes are in: