Skip to content

Commit 6993e90

Browse files
committed
fix for Creating Snippet from Selection crashes Notepad++ ffes#14
1 parent 78ec2da commit 6993e90

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Snippets.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ void Snippet::SetBeforeSelection(LPCSTR txt)
150150
}
151151

152152
// Convert from UTF-8 to WCHAR and store
153-
size_t size = MultiByteToWideChar(CP_UTF8, 0, txt, (int) len, NULL, 0);
154-
WCHAR* wBuffer = (WCHAR*) malloc(size);
155-
ZeroMemory(wBuffer, size);
156-
MultiByteToWideChar(CP_UTF8, 0, txt, (int) len, wBuffer, size);
153+
size_t sizeInChars = MultiByteToWideChar(CP_UTF8, 0, txt, (int) (len + 1), NULL, 0);
154+
WCHAR* wBuffer = (WCHAR*) malloc(sizeInChars * sizeof(WCHAR));
155+
ZeroMemory(wBuffer, sizeInChars * sizeof(WCHAR));
156+
MultiByteToWideChar(CP_UTF8, 0, txt, (int) (len + 1), wBuffer, (int)sizeInChars);
157157
WSetBeforeSelection(wBuffer);
158158
free(wBuffer);
159159
}

0 commit comments

Comments
 (0)