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

Silence false positive unaligned pointer access warning #118

Merged
merged 1 commit into from
Jan 10, 2019

Conversation

twasilczyk
Copy link
Contributor

This is an issue for Android (ARM) platform, throws a compiler warning.

@@ -330,9 +331,10 @@ int parse_mod(char *optarg, struct modattr *modmsg)
ptr++;
}

if (sscanf(++ptr, "%x.%hhx.%16s", &modmsg->cf.can_id,
Copy link
Member

Choose a reason for hiding this comment

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

Does the warning disappear when you cast the value with
(canid_t *)&modmsg->cf.can_id
??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it doesn't.

/usr/local/google/home/twasilczyk/android/adler/can-utils/cangw.c:333:48: warning: taking address of packed member 'cf' of class or structure 'modattr' may result in an unaligned pointer value [-Waddress-of-packed-member]
if (sscanf(++ptr, "%x.%hhx.%16s", (canid_t *)&modmsg->cf.can_id,
^~~~~~~~~~~~~~~~~
1 warning generated.

This is not just a warning - ARM cpus may crash on unaligned pointer access.

Copy link
Member

Choose a reason for hiding this comment

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

I googled the warning - and clang 4.x just creates a false positive here. The can_id is the first and aligned value in the struct modattr. So no chance to make ARM CPUs crash on this.
Even if it doesn't win a design price I would apply your patch. But the commit message should not contain a "fix unaligned pointer access" (which is simply wrong) but something like "silence false positive clang warning" where you should point out that the warning does not fit to the data structure in question.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'm just trying to debug an issue on my system and fixing everything that's fishy.

Copy link
Member

Choose a reason for hiding this comment

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

Merged you patch. For now it looks the best approach to go.
Happy debugging!
BR Oliver

@twasilczyk twasilczyk force-pushed the master branch 2 times, most recently from 9af09d1 to 3947d88 Compare January 10, 2019 18:04
This is a warning coming up on Android (ARM) platform.
Clang 4.x creates a false positive here: the can_id is the first
(and aligned) value in the packed struct modattr, so it's always
aligned if the struct itself is aligned.
@twasilczyk twasilczyk changed the title Fix unaligned pointer access. Silence false positive unaligned pointer access warning Jan 10, 2019
@hartkopp hartkopp merged commit 8991b5c into linux-can:master Jan 10, 2019
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.

2 participants