Skip to content

Commit 5967a90

Browse files
committed
sdl3: Use SDL_strndup() to copy the string
1 parent 6dc4729 commit 5967a90

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

demo/sdl3/nuklear_sdl3_renderer.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,9 @@ nk_sdl_clipboard_copy(nk_handle usr, const char *text, int len)
199199
{
200200
char *str = 0;
201201
(void)usr;
202-
if (!len) return;
203-
str = (char*)SDL_malloc((size_t)len+1);
204-
if (!str) return;
205-
SDL_memcpy(str, text, (size_t)len);
206-
str[len] = '\0';
202+
if (len <= 0 || text == NULL) return;
203+
str = SDL_strndup(text, (size_t)len);
204+
if (str == NULL) return;
207205
SDL_SetClipboardText(str);
208206
SDL_free((void*)str);
209207
}

0 commit comments

Comments
 (0)