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

core/sched.c: fix undefined behavior on 8-bit/16-bit #18573

Merged
merged 1 commit into from
Sep 10, 2022

Conversation

maribu
Copy link
Member

@maribu maribu commented Sep 9, 2022

Contribution description

An 1 << x with x >= 15 is undefined behavior on 8-bit / 16-bit machines (which typically have sizeof(int) == 2).

Using 1UL << x is safe for x <= 31, which is large enough to make use of the full 32 bits in runqueue_bitcache.

In addition, a static_assert() is added to enforce that SCHED_PRIO_LEVELS is never set to anything larger than 32.

Testing procedure

Code review should be sufficient IMO.

Issues/PRs references

None

An `1 << x` with `x >= 15` is undefined behavior on 8-bit / 16-bit
machines (which typically have `sizeof(int) == 2`).

Using `1UL << x` is safe for `x <= 31`, which is large enough to make
use of the full 32 bits in `runqueue_bitcache`.

In addition, a `static_assert()` is added to enforce that
`SCHED_PRIO_LEVELS` is never set to anything larger than 32.
@maribu maribu requested a review from kaspar030 as a code owner September 9, 2022 19:56
@maribu maribu added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 9, 2022
@github-actions github-actions bot added the Area: core Area: RIOT kernel. Handle PRs marked with this with care! label Sep 9, 2022
@bergzand bergzand merged commit 7fce013 into RIOT-OS:master Sep 10, 2022
@maribu maribu added this to the Release 2022.10 milestone Oct 14, 2022
@maribu maribu deleted the core/sched.c branch January 21, 2023 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: core Area: RIOT kernel. Handle PRs marked with this with care! CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants