diff options
-rw-r--r-- | engines/sci/engine/segment.h | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/engines/sci/engine/segment.h b/engines/sci/engine/segment.h index 281837d921..f9d151cc83 100644 --- a/engines/sci/engine/segment.h +++ b/engines/sci/engine/segment.h @@ -795,13 +795,14 @@ public: }; byte *data = (byte *)_data; + byte *end = data + _size; byte *source; byte *target; if (flags & kArrayTrimLeft) { target = data; source = data; - while (*source != '\0' && *source != showChar && *source <= kWhitespaceBoundary) { + while (source < end && *source != '\0' && *source != showChar && *source <= kWhitespaceBoundary) { ++source; } memmove(target, source, Common::strnlen((char *)source, _size - 1) + 1); @@ -817,29 +818,29 @@ public: if (flags & kArrayTrimCenter) { target = data; - while (*target && *target <= kWhitespaceBoundary && *target != showChar) { + while (target < end && *target != '\0' && *target <= kWhitespaceBoundary && *target != showChar) { ++target; } - if (*target) { - while (*target && (*target > kWhitespaceBoundary || *target == showChar)) { + if (*target != '\0') { + while (target < end && *target != '\0' && (*target > kWhitespaceBoundary || *target == showChar)) { ++target; } - if (*target) { + if (*target != '\0') { source = target; - while (*source) { - while (*source && *source <= kWhitespaceBoundary && *source != showChar) { + while (*source != '\0') { + while (source < end && *source != '\0' && *source <= kWhitespaceBoundary && *source != showChar) { ++source; } - while (*source && (*source > kWhitespaceBoundary || *source == showChar)) { + while (source < end && *source != '\0' && (*source > kWhitespaceBoundary || *source == showChar)) { *target++ = *source++; } } --source; - while (source > target && (*source <= kWhitespaceBoundary || *source >= kAsciiBoundary) && *source != showChar) { + while (source >= data && source > target && (*source <= kWhitespaceBoundary || *source >= kAsciiBoundary) && *source != showChar) { --source; } ++source; |