From 377cf606dd6c0e071907c263ffecd37a63ba96e7 Mon Sep 17 00:00:00 2001 From: Peter Kohaut Date: Thu, 18 Jul 2019 00:40:31 +0200 Subject: [PATCH] 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. --- common/ustr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/ustr.cpp b/common/ustr.cpp index c0a2412b595..520016d5158 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; }