Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/elfmz/far2l.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelfmz <fenix1905@tut.by>2022-02-06 02:33:32 +0300
committerelfmz <fenix1905@tut.by>2022-02-06 02:33:32 +0300
commit058ab0394bc50ee585da1f6029d867793fb00c53 (patch)
tree7eadbec11eee284c460572bd76f3f3e5d2a72771 /far2l/src/filestr.cpp
parent3f0135063b6e9e6bf3eea3f0a94cc4112b22b874 (diff)
Editor: preserve invalid UTF8 sequences (fix #1233)
Diffstat (limited to 'far2l/src/filestr.cpp')
-rw-r--r--far2l/src/filestr.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/far2l/src/filestr.cpp b/far2l/src/filestr.cpp
index 0ff255ee..98a05d52 100644
--- a/far2l/src/filestr.cpp
+++ b/far2l/src/filestr.cpp
@@ -694,7 +694,7 @@ GetFileString::GetFileString(File& SrcFile):
LastLength(0),
LastString(nullptr),
LastResult(0),
- Buffer(128)
+ Buffer(128, L'\0')
{
}
@@ -723,6 +723,8 @@ int GetFileString::PeekString(LPWSTR* DestStr, UINT nCodePage, int& Length)
return LastResult;
}
+static wchar_t s_wchnul = 0;
+
int GetFileString::GetString(LPWSTR* DestStr, UINT nCodePage, int& Length)
{
if(Peek)
@@ -774,7 +776,15 @@ int GetFileString::GetString(LPWSTR* DestStr, UINT nCodePage, int& Length)
}
- if (nExitCode == 1)
+ if (nExitCode != 1)
+ return nExitCode;
+
+ if (nCodePage == CP_UTF8)
+ {
+ MB2Wide(Str, Length, Buffer);
+ Length = Buffer.size();
+ }
+ else
{
DWORD Result = ERROR_SUCCESS;
int nResultLength = 0;
@@ -825,9 +835,11 @@ int GetFileString::GetString(LPWSTR* DestStr, UINT nCodePage, int& Length)
Buffer[nResultLength] = L'\0';
}
Length = nResultLength;
- *DestStr = &Buffer[0];
}
- return nExitCode;
+
+ *DestStr = Length ? &Buffer[0] : &s_wchnul;
+
+ return 1;
}