summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/console.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/console.c b/src/console.c
index 09d3116..af105b2 100644
--- a/src/console.c
+++ b/src/console.c
@@ -384,22 +384,23 @@ void BarConsoleEraseLine (int mode) {
void BarConsoleSetClipboard(const char* text) {
WCHAR* wideString;
HANDLE stringHandle;
- size_t wideSize;
+ size_t wideSize, wideBytes;
wideSize = MultiByteToWideChar(CP_UTF8, 0, text, -1, NULL, 0);
- wideString = calloc(1, (wideSize + 1) * sizeof(WCHAR));
+ wideBytes = wideSize * sizeof(WCHAR);
+ wideString = malloc(wideBytes);
if (!wideString)
return;
MultiByteToWideChar(CP_UTF8, 0, text, -1, wideString, wideSize);
- stringHandle = GlobalAlloc(GMEM_MOVEABLE, wideSize);
+ stringHandle = GlobalAlloc(GMEM_MOVEABLE, wideBytes);
if (!stringHandle) {
free(wideString);
return;
}
- memcpy(GlobalLock(stringHandle), wideString, wideSize);
+ memcpy(GlobalLock(stringHandle), wideString, wideBytes);
GlobalUnlock(stringHandle);