[NOTEPAD] Treat empty file correctly (#5057)

#5012 had a regression on opening an empty file.
CORE-14641, CORE-18826
This commit is contained in:
Katayama Hirofumi MZ 2023-02-09 21:54:20 +09:00 committed by GitHub
parent 06b25bc9dd
commit 1b20c7312f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -179,6 +179,22 @@ ReadText(HANDLE hFile, HLOCAL *phLocal, ENCODING *pencFile, EOLN *piEoln)
if (dwSize == INVALID_FILE_SIZE)
goto done;
if (dwSize == 0) // If file is empty
{
hNewLocal = LocalReAlloc(*phLocal, sizeof(UNICODE_NULL), LMEM_MOVEABLE);
pszNewText = LocalLock(hNewLocal);
if (hNewLocal == NULL || pszNewText == NULL)
goto done;
*pszNewText = UNICODE_NULL;
LocalUnlock(hNewLocal);
*phLocal = hNewLocal;
*piEoln = EOLN_CRLF;
*pencFile = ENCODING_UTF8;
return TRUE;
}
hMapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if (hMapping == NULL)
goto done;