Skip to content

Signed integer overflow in INT32_BITFIELD_SET#247

Open
udf2457 wants to merge 1 commit into
krallin:masterfrom
udf2457:overflow
Open

Signed integer overflow in INT32_BITFIELD_SET#247
udf2457 wants to merge 1 commit into
krallin:masterfrom
udf2457:overflow

Conversation

@udf2457

@udf2457 udf2457 commented Jun 23, 2026

Copy link
Copy Markdown

When i % 32 == 31, 1 << 31 shifts into the sign bit of a signed int. This is undefined behavior in C.

A quick-fix would be using a signed constant (1U << (i % 32)).

But refactoring INT32_BITFIELD_SET to int32_bitfield_set introduces type-safety.

When i % 32 == 31, 1 << 31 shifts into the sign bit of a signed int. This is undefined behavior in C.

A quick-fix would be using a signed constant `(1U << (i % 32))`.

But refactoring `INT32_BITFIELD_SET` to `int32_bitfield_set` introduces type-safety.
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.

1 participant