nicbarker / clay

High performance UI layout library in C.
https://nicbarker.com/clay
zlib License
1.29k stars 31 forks source link

[Bug] Fix null pointer deref in Clay_SetPointerState #33

Closed SogoCZE closed 1 month ago

SogoCZE commented 1 month ago

In some situations mapItem in Clay_SetPointerState can end up being null which results in to crash (because elementId is being accessed on null mapItem).

An example of this behaviour can be seen when you have an empty layout with only one text:

Clay_BeginLayout();

CLAY_TEXT(
    CLAY_ID("HelloWorldText"), 
    CLAY_STRING("Hello World!"),
    CLAY_TEXT_CONFIG(
        .fontId = FONT_ID_BODY_24, 
        .fontSize = 24,
         .textColor = {255, 0, 0, 255}
    )
);

return Clay_EndLayout();
nicbarker commented 1 month ago

Hello, thanks for reporting this one! Taking a look now 👀

nicbarker commented 1 month ago

Seems like the entire second half of that if statement was just an incorrect case. Must have been left over from a refactor or something. Nice catch!