From 051973a54610ae3796af9da2a33db8a12a84b144 Mon Sep 17 00:00:00 2001 From: looterz Date: Wed, 17 Feb 2016 17:07:06 -0600 Subject: [PATCH] Cleaned up and patched ace_clipboard. --- extensions/clipboard/ace_clipboard.cpp | 59 ++++++++++++++++---------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/extensions/clipboard/ace_clipboard.cpp b/extensions/clipboard/ace_clipboard.cpp index cdd5f7c423..bade6f5b67 100644 --- a/extensions/clipboard/ace_clipboard.cpp +++ b/extensions/clipboard/ace_clipboard.cpp @@ -1,7 +1,7 @@ /* * ace_clipboard.cpp * - * Takes a string and copies it to the clipboard; bypasses arma 8k clippy limit. + * Takes a string and copies it to the clipboard; bypasses arma 8k clippy limit. Windows only. * * Takes: * Localized string as string @@ -9,7 +9,10 @@ * Returns: * None */ + #include "shared.hpp" + +#include #include #include @@ -30,44 +33,56 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function) { } if (!strcmp(function, "version")) { - strncpy(output, ACE_FULL_VERSION_STR, outputSize); + strncpy_s(output, outputSize, ACE_FULL_VERSION_STR, _TRUNCATE); EXTENSION_RETURN(); } -#ifdef _WIN32 + #ifndef _WIN32 + EXTENSION_RETURN(); + #endif - if (!strcmp(function, "--COMPLETE--")) { + if (!strcmp(function, "--COMPLETE--")) + { HGLOBAL hClipboardData = GlobalAlloc(GMEM_FIXED, gClipboardData.length() + 1); - if (!hClipboardData) { + if (!hClipboardData) + { result = "GlobalAlloc() failed, GetLastError=" + GetLastError(); gClipboardData = ""; EXTENSION_RETURN(); } char *pClipboardData = (char *)GlobalLock(hClipboardData); - if (!pClipboardData) { + if (!pClipboardData) + { result = "GlobalLock() failed, GetLastError=" + GetLastError(); gClipboardData = ""; EXTENSION_RETURN(); } - memcpy(pClipboardData, gClipboardData.c_str(), gClipboardData.length()); - pClipboardData[gClipboardData.length() + 1] = 0x00; + + strncpy_s(pClipboardData, gClipboardData.length(), gClipboardData.c_str(), _TRUNCATE); GlobalUnlock(hClipboardData); - if (!OpenClipboard(NULL)) { + if (!OpenClipboard(NULL)) + { result = "OpenClipboard() failed, GetLastError=" + GetLastError(); } - else { - if (!EmptyClipboard()) { + else + { + if (!EmptyClipboard()) + { result = "OpenClipboard() failed, GetLastError=" + GetLastError(); } - else { - if (!SetClipboardData(CF_TEXT, hClipboardData)) { + else + { + if (!SetClipboardData(CF_TEXT, hClipboardData)) + { result = "SetClipboardData() failed, GetLastError=" + GetLastError(); } - else { - if (!CloseClipboard()) { + else + { + if (!CloseClipboard()) + { result = "CloseClipboard() failed, GetLastError=" + GetLastError(); } } @@ -75,16 +90,16 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function) { } gClipboardData = ""; - } else { + } + else + { gClipboardData = gClipboardData + cur_input; } - end: - if(result.length() > 1) - memcpy(output, result.c_str(), result.length()+1); - - #endif + if (result.length() > 1) + { + strncpy_s(output, outputSize, result.c_str(), _TRUNCATE); + } EXTENSION_RETURN(); } -