From 8525b0b40c31adafd3312d0a4fea17c249465804 Mon Sep 17 00:00:00 2001 From: TakaRikka Date: Wed, 19 Aug 2026 19:06:53 -0700 Subject: [PATCH] enc's suggestions --- src/dusk/mods/svc/ui.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/dusk/mods/svc/ui.cpp b/src/dusk/mods/svc/ui.cpp index 561448d138..304c4eb57b 100644 --- a/src/dusk/mods/svc/ui.cpp +++ b/src/dusk/mods/svc/ui.cpp @@ -1044,29 +1044,28 @@ ModResult ui_get_clipboard_text(LoadedMod& mod, char* buffer, size_t bufferSize, *outLength = 0; } + std::string text; if (SDL_HasClipboardText()) { - char* text_ptr = SDL_GetClipboardText(); - std::string text = text_ptr ? text_ptr : ""; - SDL_free(text_ptr); - + char* textPtr = SDL_GetClipboardText(); + text = textPtr != nullptr ? textPtr : ""; + SDL_free(textPtr); if (text.empty()) { return MOD_ERROR; } - - if (outLength != nullptr) { - *outLength = text.size(); - } - - if (bufferSize < text.size() + 1) { - return MOD_INVALID_ARGUMENT; - } - - memcpy(buffer, text.c_str(), text.size() + 1); - buffer[text.size()] = '\0'; - } else { - *buffer = '\0'; } + if (outLength != nullptr) { + *outLength = text.size(); + } + + if (buffer == nullptr) { + return MOD_OK; + } + if (bufferSize < text.size() + 1) { + return MOD_INVALID_ARGUMENT; + } + + memcpy(buffer, text.c_str(), text.size() + 1); return MOD_OK; } @@ -1410,7 +1409,7 @@ ModResult ui_dialog_add_action( ModResult ui_get_clipboard_text(ModContext* ctx, char* buffer, size_t bufferSize, size_t* outLength) { auto* mod = mod_from_context(ctx); - if (mod == nullptr || buffer == nullptr) { + if (mod == nullptr || (buffer == nullptr && bufferSize != 0)) { return MOD_INVALID_ARGUMENT; }