stb icon indicating copy to clipboard operation
stb copied to clipboard

stb_ds: Fix `d[i] << 24` undefined behaviour due to overflow

Open darkuranium opened this issue 1 year ago • 1 comments

Because of int promotion, d[i] << 24 overflows an int, resulting in UB.

Found via ubsan in clang 18:

stb/stb_ds.h:1124:67: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior stb/stb_ds.h:1124:67

darkuranium avatar Sep 10 '24 17:09 darkuranium