-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Open
Copy link
Labels
area: Base OSBase OS Library (lib/os)Base OS Library (lib/os)bugThe issue is a bug, or the PR is fixing a bugThe issue is a bug, or the PR is fixing a bugpriority: mediumMedium impact/importance bugMedium impact/importance bug
Description
Describe the bug
On file include/zephyr/sys/util.h
:
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
...
#define DIV_ROUND_CLOSEST(n, d)
...
- If zero is passed as denominator, undefined behavior will follow with these
preprocessor macros:
For DIV_ROUND_UP only:
- If there's an overflow when doing (n + d), wrong values will be returned;
- Using negative operands returns wrong values, as it should round up towards
positive infinity.
These macros are used extensively on Zephyr code, but I'm not sure if there's any
way to pass a zero as denominator when used, or if wrong calculations are being
made:
$ grep -RI DIV_ROUND_UP | wc -l
294
$ grep -RI DIV_ROUND_CLOSEST
43
The user might face issues if they use it in their application:
* Misc utilities usable by the kernel and application code.
Regression
- This is a regression.
Steps to reproduce
No response
Relevant log output
Impact
Not sure
Environment
No response
Additional Context
No response
Metadata
Metadata
Labels
area: Base OSBase OS Library (lib/os)Base OS Library (lib/os)bugThe issue is a bug, or the PR is fixing a bugThe issue is a bug, or the PR is fixing a bugpriority: mediumMedium impact/importance bugMedium impact/importance bug