From ec1530d488922c56f5ffc603c484714865786c70 Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Tue, 4 Oct 2005 12:57:04 +0000 Subject: [PATCH] Notepad: Fixed a bug when opening files with no characters other than byte order marks svn path=/trunk/; revision=18260 --- reactos/subsys/system/notepad/text.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/reactos/subsys/system/notepad/text.c b/reactos/subsys/system/notepad/text.c index a5c06516fdc..43d1c6ad2f1 100644 --- a/reactos/subsys/system/notepad/text.c +++ b/reactos/subsys/system/notepad/text.c @@ -130,16 +130,27 @@ BOOL ReadText(HANDLE hFile, LPWSTR *ppszText, DWORD *pdwTextLen, int *piEncoding else goto done; - dwCharCount = MultiByteToWideChar(iCodePage, 0, (LPCSTR)&pBytes[dwPos], dwSize - dwPos, NULL, 0); - if (dwCharCount == 0) - goto done; + if ((dwSize - dwPos) > 0) + { + dwCharCount = MultiByteToWideChar(iCodePage, 0, (LPCSTR)&pBytes[dwPos], dwSize - dwPos, NULL, 0); + if (dwCharCount == 0) + goto done; + } + else + { + /* special case for files with no characters (other than BOMs) */ + dwCharCount = 0; + } pszAllocText = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, (dwCharCount + 1) * sizeof(WCHAR)); if (!pszAllocText) goto done; - if (!MultiByteToWideChar(iCodePage, 0, (LPCSTR)&pBytes[dwPos], dwSize - dwPos, pszAllocText, dwCharCount)) - goto done; + if ((dwSize - dwPos) > 0) + { + if (!MultiByteToWideChar(iCodePage, 0, (LPCSTR)&pBytes[dwPos], dwSize - dwPos, pszAllocText, dwCharCount)) + goto done; + } pszAllocText[dwCharCount] = '\0'; pszText = pszAllocText;