diff options
-rw-r--r-- | engines/sludge/utf8.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/engines/sludge/utf8.cpp b/engines/sludge/utf8.cpp index 61c297571b..bfcaec5ab9 100644 --- a/engines/sludge/utf8.cpp +++ b/engines/sludge/utf8.cpp @@ -75,11 +75,13 @@ Common::U32String UTF8Converter::convertUtf8ToUtf32(const Common::String &str) { /* utf32 index => original byte offset */ int UTF8Converter::getOriginOffset(int origIdx) { - int offs = 0; - - while (origIdx > 0 && _str[offs]) { + uint offs = 0; + while (origIdx > 0 && offs < _str.size()) { // increment if it's not the start of a utf8 sequence - (void)(isutf(_str[++offs]) || isutf(_str[++offs]) || isutf(_str[++offs]) || ++offs); + (void)( (++offs < _str.size() && isutf(_str[offs])) || + (++offs < _str.size() && isutf(_str[offs])) || + (++offs < _str.size() && isutf(_str[offs])) || + ++offs); origIdx--; } return offs; |