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(MiscDrivers): MSDK-1240: Clear out of bounds warnings seen with GCC v13.2 #852

Merged
merged 2 commits into from
Jan 12, 2024

Conversation

ahmetalincak
Copy link
Contributor

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:

  1. MXC_TFT_Init function: Optional and tested for both GCC Versions (10.3 and 13.2) on MAX78000 kws20_demo.
  2. MXC_TFT_Printf function: This one works incorrect when using GCC v13.2 - so should be merged. Tested with MAX32662 Demo Example.

@ahmetalincak ahmetalincak force-pushed the fix/tft_ssd2119-warnings branch from ba44aab to a435a11 Compare January 2, 2024 18:35
@ahmetalincak ahmetalincak requested review from rotx-eva and removed request for rotx-eva January 2, 2024 18:53
@@ -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_) {
Copy link

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?

Copy link
Contributor Author

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.

Copy link

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_);
Copy link

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?

Copy link
Contributor Author

@ahmetalincak ahmetalincak Jan 9, 2024

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.

Copy link

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;

@ahmetalincak ahmetalincak requested a review from rotx-eva January 9, 2024 07:28
Copy link

@rotx-eva rotx-eva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve casts

@ahmetalincak ahmetalincak force-pushed the fix/tft_ssd2119-warnings branch from 5d3bc9f to 5a42cd3 Compare January 10, 2024 11:35
@ahmetalincak ahmetalincak requested a review from rotx-eva January 11, 2024 08:23
Copy link
Contributor

@Jake-Carter Jake-Carter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ahmetalincak

@Jake-Carter Jake-Carter merged commit b71d6f5 into main Jan 12, 2024
@Jake-Carter Jake-Carter deleted the fix/tft_ssd2119-warnings branch January 12, 2024 01:16
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.

3 participants