From f43d6e82c3fb59f25189c745c5ca5ff1d2e3c161 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 27 Nov 2022 02:54:36 +0100 Subject: mgl_window_get_clipboard_string set ptr to NULL after free when failing --- include/mgl/window/window.h | 1 + src/window/window.c | 1 + 2 files changed, 2 insertions(+) diff --git a/include/mgl/window/window.h b/include/mgl/window/window.h index ed50dcb..350421d 100644 --- a/include/mgl/window/window.h +++ b/include/mgl/window/window.h @@ -126,6 +126,7 @@ bool mgl_window_get_clipboard(mgl_window *self, mgl_clipboard_callback callback, This function returns false if there is nothing to copy, or if the clipboard contains clipboard data that is not a string or if it fails to copy the data for any other reason. + Note: The string is not null terminated. */ bool mgl_window_get_clipboard_string(mgl_window *self, char **str, size_t *size); void mgl_window_set_key_repeat_enabled(mgl_window *self, bool enabled); diff --git a/src/window/window.c b/src/window/window.c index 5ae4d3f..709f4b1 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -1221,6 +1221,7 @@ bool mgl_window_get_clipboard_string(mgl_window *self, char **str, size_t *size) const bool success = mgl_window_get_clipboard(self, clipboard_copy_string_callback, &callback_data, MGL_CLIPBOARD_TYPE_STRING); if(!success) { free(*str); + *str = NULL; *size = 0; } return success; -- cgit v1.2.3