Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect TextIsEqual from NULLs #2121

Merged
merged 1 commit into from
Nov 9, 2021

Conversation

lukekras
Copy link
Contributor

@lukekras lukekras commented Nov 9, 2021

I was running the core_input_gamepad example program with a PS4 Controller and disconnected and reconnected the USB cable. The program crashed with a EXC_BAD_ACCESS (SIGSEGV). The SIGSEGV happens in core_input_gamepad.c when GetGamepadName returns a NULL (when the gamepad is disconnected) and TextIsEqual attempts to compare two strings with one of them a NULL. TextIsEqual uses strcmp which has undefined behaviour when one or both strings are NULL. It seemed like a good place to put a NULL check was in TextIsEqual. I think that when one of the strings being compared was NULL, returning false would be always the desired behaviour. Also I've returned false instead of the variable result because if one or both of the strings is NULL, you will always want to return false. Someone may change the default result variable to true, and then the check would break.

I've only tested this on macOS Big Sur Intel.

@raysan5 raysan5 merged commit 8ec5b2d into raysan5:master Nov 9, 2021
@raysan5
Copy link
Owner

raysan5 commented Nov 9, 2021

@lukekras Thanks! Nice improvement!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants