https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1b20c7312fa2e03f4fbc1…
commit 1b20c7312fa2e03f4fbc11d81415043d5c30a3e2
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Thu Feb 9 21:54:20 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Thu Feb 9 21:54:20 2023 +0900
[NOTEPAD] Treat empty file correctly (#5057)
#5012 had a regression on opening an empty file.
CORE-14641, CORE-18826
---
base/applications/notepad/text.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/base/applications/notepad/text.c b/base/applications/notepad/text.c
index 3ce3a889bfe..0025ddf9dac 100644
--- a/base/applications/notepad/text.c
+++ b/base/applications/notepad/text.c
@@ -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;