bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 12 forks source link

Fix left shift warnings #619

Closed woollybah closed 1 year ago

woollybah commented 1 year ago

Use of Base64 sometimes generates warnings when compiled with UndefinedBehaviorSanitizer (UBS).

src/bcc/.bmx/base64.bmx.release.macos.arm64.c:146:71: runtime error: left shift of 218 by 24 places cannot be represented in type 'BBINT' (aka 'int')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/bcc/.bmx/base64.bmx.release.macos.arm64.c:146:71 in 
src/bcc/.bmx/base64.bmx.release.macos.arm64.c:144:65: runtime error: left shift of 143 by 24 places cannot be represented in type 'BBINT' (aka 'int')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/bcc/.bmx/base64.bmx.release.macos.arm64.c:144:65 in 
src/bcc/.bmx/base64.bmx.release.macos.arm64.c:148:72: runtime error: left shift of 177 by 24 places cannot be represented in type 'BBINT' (aka 'int')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/bcc/.bmx/base64.bmx.release.macos.arm64.c:148:72 in 

We should probably change the code to work without shifting "out of bounds".

GWRon commented 1 year ago

Dunno if this is of importance - but in expr.bmx / Type TConstExpr there is also some bitshifting happening. Dunno how big values can become where.

You might at least have a look at it to ensure it works correctly.