mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-09 04:16:34 +00:00
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.
This commit is contained in:
parent
afb9ff0048
commit
377cf606dd
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user