From c348fa0f9b35f61ada33bb630066aa1a0e03f21c Mon Sep 17 00:00:00 2001 From: Alex Murkoff <413x1nkp@gmail.com> Date: Mon, 22 Jul 2024 04:05:06 +0000 Subject: [PATCH] fix: implied return and NULL cast to uint64_t (#171) * fix: add return statements to wrapper functions in cute_draw.h the wrapper functions in question are calling internal functions that return the matching bool, i assume the return statement was implied * fix: fix possible undefined behavior from NULL cast 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) --- include/cute_draw.h | 4 ++-- src/cute_audio.cpp | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/include/cute_draw.h b/include/cute_draw.h index 4fd131906..0d7747282 100644 --- a/include/cute_draw.h +++ b/include/cute_draw.h @@ -1620,8 +1620,8 @@ typedef bool (text_markup_info_fn)(const char* text, MarkupInfo info, const Text CF_INLINE void text_get_markup_info(text_markup_info_fn* fn, const char* text, v2 position, int num_chars_to_draw = -1) { cf_text_get_markup_info((cf_text_markup_info_fn*)fn, text, position, num_chars_to_draw); } CF_INLINE void push_text_effect_active(bool effects_on) { cf_push_text_effect_active(effects_on); } -CF_INLINE bool pop_text_effect_active() { cf_pop_text_effect_active(); } -CF_INLINE bool peek_text_effect_active() { cf_peek_text_effect_active(); } +CF_INLINE bool pop_text_effect_active() { return cf_pop_text_effect_active(); } +CF_INLINE bool peek_text_effect_active() { return cf_peek_text_effect_active(); } CF_INLINE void render_settings_filter(Filter filter) { cf_render_settings_filter(filter); } CF_INLINE void render_settings_push_viewport(Rect viewport) { cf_render_settings_push_viewport(viewport); } diff --git a/src/cute_audio.cpp b/src/cute_audio.cpp index 333c53d31..e2c51a567 100644 --- a/src/cute_audio.cpp +++ b/src/cute_audio.cpp @@ -33,9 +33,8 @@ CF_Audio cf_audio_load_ogg(const char* path) CF_Audio src = cf_audio_load_ogg_from_memory(data, (int)size); CF_FREE(data); return src; - } else { - return { NULL }; } + return { 0 }; } CF_Audio cf_audio_load_wav(const char* path) @@ -46,9 +45,8 @@ CF_Audio cf_audio_load_wav(const char* path) auto src = cf_audio_load_wav_from_memory(data, (int)size); CF_FREE(data); return (CF_Audio)src; - } else { - return { NULL }; } + return { 0 }; } CF_Audio cf_audio_load_ogg_from_memory(void* memory, int byte_count)