diff --git a/winpr/libwinpr/crt/unicode.c b/winpr/libwinpr/crt/unicode.c index e4f7ae66d..136df98c8 100644 --- a/winpr/libwinpr/crt/unicode.c +++ b/winpr/libwinpr/crt/unicode.c @@ -403,13 +403,12 @@ int ConvertToUnicode(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cb cchWideChar = MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, NULL, 0); allocate = TRUE; } + else if (!(*lpWideCharStr)) + allocate = TRUE; if (cchWideChar < 1) return 0; - if (!(*lpWideCharStr)) - allocate = TRUE; - if (allocate) { *lpWideCharStr = (LPWSTR)calloc(cchWideChar + 1, sizeof(WCHAR)); @@ -473,13 +472,12 @@ int ConvertFromUnicode(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, NULL, 0, NULL, NULL); allocate = TRUE; } + else if (!(*lpMultiByteStr)) + allocate = TRUE; if (cbMultiByte < 1) return 0; - if (!(*lpMultiByteStr)) - allocate = TRUE; - if (allocate) { *lpMultiByteStr = (LPSTR)calloc(1, cbMultiByte + 1);