aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kohaut2019-07-18 00:40:31 +0200
committerPeter Kohaut2019-07-18 01:00:01 +0200
commit377cf606dd6c0e071907c263ffecd37a63ba96e7 (patch)
tree0260ab00d69fda0eba049c086cc9e8c82490329a
parentafb9ff00484ce9aa5cd53afec826f211fd569809 (diff)
downloadscummvm-rg350-377cf606dd6c0e071907c263ffecd37a63ba96e7.tar.gz
scummvm-rg350-377cf606dd6c0e071907c263ffecd37a63ba96e7.tar.bz2
scummvm-rg350-377cf606dd6c0e071907c263ffecd37a63ba96e7.zip
COMMON: Fix U32String initialization issues
Bug 1: If the original C string contained chars > 127 they would be stored as huge u32 numbers due to the underflow as char is signed. It still might end-up with invalid UTF32 characters, but now the caller can control it. Bug 2: The inline storage was not properly initialized when U32String was initalized from shorter non-UTF32 strings.
-rw-r--r--common/ustr.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/common/ustr.cpp b/common/ustr.cpp
index c0a2412b59..520016d515 100644
--- a/common/ustr.cpp
+++ b/common/ustr.cpp
@@ -90,7 +90,7 @@ U32String::U32String(const char *beginP, const char *endP) : _size(0), _str(_sto
initWithCStr(beginP, endP - beginP);
}
-U32String::U32String(const String &str) : _size(0) {
+U32String::U32String(const String &str) : _size(0), _str(_storage) {
initWithCStr(str.c_str(), str.size());
}
@@ -423,7 +423,7 @@ void U32String::initWithCStr(const char *str, uint32 len) {
// Copy the string into the storage area
for (size_t idx = 0; idx < len; ++idx, ++str)
- _str[idx] = *str;
+ _str[idx] = (byte)(*str);
_str[len] = 0;
}