-
Notifications
You must be signed in to change notification settings - Fork 349
common.h: Make IS_ALIGNED() safe for testing with alignment == 0 #10322
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |
|
|
||
| /* Align the number to the nearest alignment value */ | ||
| #ifndef IS_ALIGNED | ||
| #define IS_ALIGNED(size, alignment) ((size) % (alignment) == 0) | ||
| #define IS_ALIGNED(size, alignment) (!(alignment) || (size) % (alignment) == 0) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we are using Zephyr version (included above) and this version of IS_ALIGNED wont be used (#ifndef IS_ALIGNED) btw alignment 0 is incorrect anyway so maybe this macro was called somewhere where it shouldnt?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whether it is incorrect or not, is a matter of definition. But apparently this change is useless on its own, so I'll close it. |
||
| #endif | ||
|
|
||
| /* Treat zero as a special case because it wraps around */ | ||
|
|
||
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.
The macro lacks documentation explaining the behavior when alignment is 0. Add a comment clarifying that zero alignment is treated as always aligned (returns true), which prevents division by zero in the modulo operation.