Closed OetkenPurveyorOfCode closed 2 hours ago
Thanks! 4294967295 is hex 0xFFFFFFFF, looks like point.y can be -1 (or generally negative) in some situations. The component types in POINT are signed numbers, and left shifting a negative signed number is UB.
I guess I'll just skip the entire PostMessage when the x or y values in POINT are negative.
Hang on, its acutally defined behaviour. I guess UBSAN also warns against unsigned integer overflow.
Ah right, it's casted to unsigned before the shift... then I guess shifting 1-bits out of a value is also UB, that's kinda crazy though (e.g. IMHO shifting bits out of a value is an entirely normal operation, but looks like UBSAN or the C standard disagrees).
Thanks! 4294967295 is hex 0xFFFFFFFF, looks like point.y can be -1 (or generally negative) in some situations.
The documentation says that GetCursorPos can fail and return zero in the BOOL return value.
Ah right, it's casted to unsigned before the shift... then I guess shifting 1-bits out of a value is also UB, that's kinda crazy though (e.g. IMHO shifting bits out of a value is an entirely normal operation, but looks like UBSAN or the C standard disagrees).
I guess I left integer sanitizer on in my build.
Hmm, could be the -fsanitize=unsigned-integer-overflow
, which says in the UBSAN docs "is not undefined behaviour but often unintentional".
The documentation says that GetCursorPos can fail and return zero in the BOOL return value.
...good point, I'll use the return value to skip the rest of the code. POINT point;
being uninitialized is also kind of a code-smell.
Ok, see https://github.com/floooh/sokol/commit/a5329cf1ca56408687c7771772846b0c38094ac4. Not sure if it actually fixes the unsigned integer overflow, but it's definitely better behaviour than before.
Thanks for the report!