Notepad: Fixed a bug when opening files with no characters other than byte order marks

svn path=/trunk/; revision=18260
This commit is contained in:
Nathan Woods 2005-10-04 12:57:04 +00:00
parent ec396aa21f
commit ec1530d488

View file

@ -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;