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

fix: implied return and NULL cast to uint64_t #171

Merged
merged 2 commits into from
Jul 22, 2024
Merged

fix: implied return and NULL cast to uint64_t #171

merged 2 commits into from
Jul 22, 2024

Conversation

alexlnkp
Copy link
Contributor

  • The wrapper functions in cute_draw.h are meant to return bool type, however the return values of internal cf_* functions which are called aren't stored or returned, thus making these functions return nothing. Easily fixed by calling the internal functions within the wrapper and returning the returned values.

  • In cute_audio.cpp, a NULL was returned previously. Due to CF_Audio having just one field in the struct for the data, that would mean the NULL would be cast to uint64_t. This means that comparing the return value from cf_audio_load_* functions to NULL would not yield any actual results in some scenarios, as the value would be cast to uint64_t, resulting in undefined behavior. Solution is simple, just return an empty CF_Audio struct. Then, if needed, the return value can simply be compared to 0, which would imply that either the CF_Audio wasn't yet populated, OR there was an error trying to load audio. (NOTE: Asserts can also be used here to indicate what is PRECISELY the case.)

alexlnkp added 2 commits July 22, 2024 10:15
the wrapper functions in question are calling internal functions that return the matching bool, i assume the return statement was implied
previously, a NULL was returned, which was casted to uint64_t. this is undefined behavior; now it just returns empty CF_Audio, which can easily be checked and compared (NOTE: comparing the returned CF_Audio to NULL in case of functions returning NULL would not yield anything, as NULL is first casted to uint64_t, possibly messing up the comparison to NULL)
@RandyGaul
Copy link
Owner

Thank you! These are helpful adjustments.

@RandyGaul RandyGaul merged commit c348fa0 into RandyGaul:master Jul 22, 2024
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