Skip to content

Commit

Permalink
fix: implied return and NULL cast to uint64_t (#171)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
alexlnkp authored Jul 22, 2024
1 parent 6897d40 commit c348fa0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/cute_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
6 changes: 2 additions & 4 deletions src/cute_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit c348fa0

Please sign in to comment.