News for hackers. Stuff that matters.
Re:Perfecting GLFW for Zig, and finding lurking undefined be... by kzrdude on Sunday October 31, 2021 @08:06PM (#29061729)
The problem in the article is something like this:

    int main() {
        unsigned char foo = 0x80;
        unsigned int x = foo << 24;
    }
and with ubsan enabled it says

    /app/example.c:5:30: runtime error: left shift of 128 by 24 places cannot be represented in type 'int'
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /app/example.c:5:30 in

What's non-obvious is also the rules around arithmetic. Types unsigned char and unsigned int are mentioned in my snippet but the arithmetic - the `<<` operator - performed using the type int.

There are no comments on this comment yet.