From 02b09dc8fc7716e587d2120dd0674a492d3a6eb3 Mon Sep 17 00:00:00 2001 From: Simei Yin Date: Sat, 12 Aug 2017 11:42:04 +0200 Subject: SLUDGE: Fix Common::String operator[] out of range --- engines/sludge/utf8.cpp | 10 ++++++---- 1 file 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; -- cgit v1.2.3