Notepad: Fixed a bug when opening files with no characters other than byte order marks Modified: trunk/reactos/subsys/system/notepad/text.c _____
Modified: trunk/reactos/subsys/system/notepad/text.c --- trunk/reactos/subsys/system/notepad/text.c 2005-10-04 12:41:08 UTC (rev 18259) +++ trunk/reactos/subsys/system/notepad/text.c 2005-10-04 12:57:04 UTC (rev 18260) @@ -130,16 +130,27 @@
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;