From 1e7c49969628dcd42d937d194359d11fc74ee650 Mon Sep 17 00:00:00 2001 From: Michał Cichoń Date: Tue, 25 Aug 2015 18:28:18 +0200 Subject: Fix text copied to clipboard being cropped. --- src/console.c | 9 +++++---- 1 file 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); -- cgit v1.2.3