-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Cast values to u32 if shift overflows int
Bit shifts that overflow the resulting type are undefined behavior in C. C arithmetic promotes to ints all smaller integer types. There are several places where a 32-bit unsigned value is constructed by shifting a u8 or u16 to the most significant bits. Since this overflows a signed 32-bit integer, explicitly cast to u32 to avoid the UB. Technically, an int is allowed to only be 16 bits, so any shift that could set bit 15 or higher is UB. But platforms where int is s16 are not very common, so it's likely not worth the effort to fix the code. Signed-off-by: Caleb Sander <[email protected]>
- Loading branch information
1 parent
3ca94c0
commit d5962d8
Showing
2 changed files
with
22 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters