-
Notifications
You must be signed in to change notification settings - Fork 717
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
Conversation
@@ -330,9 +331,10 @@ int parse_mod(char *optarg, struct modattr *modmsg) | |||
ptr++; | |||
} | |||
|
|||
if (sscanf(++ptr, "%x.%hhx.%16s", &modmsg->cf.can_id, |
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.
Does the warning disappear when you cast the value with
(canid_t *)&modmsg->cf.can_id
??
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.
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.
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.
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.
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.
Good point, I'm just trying to debug an issue on my system and fixing everything that's fishy.
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.
Merged you patch. For now it looks the best approach to go.
Happy debugging!
BR Oliver
9af09d1
to
3947d88
Compare
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.
This is an issue for Android (ARM) platform, throws a compiler warning.