mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Decode invalid utf-8 more gracefully (invalid bytes becomes U+FFFD)
This was SVN commit r6999.
This commit is contained in:
+8
-4
@@ -156,13 +156,17 @@ CStrW CStr8::FromUTF8() const
|
||||
unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
|
||||
if (source + extraBytesToRead >= sourceEnd)
|
||||
{
|
||||
//debug_warn("Invalid UTF-8 (fell off end)");
|
||||
return L"";
|
||||
// Error - fell of the the end of the string
|
||||
result += (wchar_t)0xFFFD;
|
||||
source++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! isLegalUTF8(source, extraBytesToRead+1)) {
|
||||
//debug_warn("Invalid UTF-8 (illegal data)");
|
||||
return L"";
|
||||
// Error - illegal data
|
||||
result += (wchar_t)0xFFFD;
|
||||
source++;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (extraBytesToRead)
|
||||
|
||||
Reference in New Issue
Block a user