From 6993e9013c61dce80f3c52c4f4ddb3242cd8910a Mon Sep 17 00:00:00 2001 From: Christian Grasser Date: Thu, 11 Oct 2018 23:21:53 +0200 Subject: [PATCH] fix for Creating Snippet from Selection crashes Notepad++ #14 --- Snippets.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Snippets.cpp b/Snippets.cpp index 36e6e40..e479e1a 100755 --- a/Snippets.cpp +++ b/Snippets.cpp @@ -150,10 +150,10 @@ void Snippet::SetBeforeSelection(LPCSTR txt) } // Convert from UTF-8 to WCHAR and store - size_t size = MultiByteToWideChar(CP_UTF8, 0, txt, (int) len, NULL, 0); - WCHAR* wBuffer = (WCHAR*) malloc(size); - ZeroMemory(wBuffer, size); - MultiByteToWideChar(CP_UTF8, 0, txt, (int) len, wBuffer, size); + size_t sizeInChars = MultiByteToWideChar(CP_UTF8, 0, txt, (int) (len + 1), NULL, 0); + WCHAR* wBuffer = (WCHAR*) malloc(sizeInChars * sizeof(WCHAR)); + ZeroMemory(wBuffer, sizeInChars * sizeof(WCHAR)); + MultiByteToWideChar(CP_UTF8, 0, txt, (int) (len + 1), wBuffer, (int)sizeInChars); WSetBeforeSelection(wBuffer); free(wBuffer); }