diff options
author | Colin Snover | 2017-01-26 15:30:04 -0600 |
---|---|---|
committer | Colin Snover | 2017-03-30 19:46:27 -0500 |
commit | 4284488244248e610cac5178fa27c6c1f51e6c58 (patch) | |
tree | 246f4513a86eaac864029b33608ffb50102df405 /engines | |
parent | 2d0c1c8ab50862136cf4c5c75e016a1def90c3e4 (diff) | |
download | scummvm-rg350-4284488244248e610cac5178fa27c6c1f51e6c58.tar.gz scummvm-rg350-4284488244248e610cac5178fa27c6c1f51e6c58.tar.bz2 scummvm-rg350-4284488244248e610cac5178fa27c6c1f51e6c58.zip |
SCI32: Improve bounds checking in SciString trim
Diffstat (limited to 'engines')
-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; |