aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Snover2017-02-08 11:49:25 -0600
committerColin Snover2017-02-08 12:05:14 -0600
commitf1d9955540076e044905afb3fd6dbc03034aacd3 (patch)
tree3b1e2c856676aceb0cd8ddd6916ffc92a5990bad
parent3aa660f4c7a4c427c895e6f45a0cf0021dd02d26 (diff)
downloadscummvm-rg350-f1d9955540076e044905afb3fd6dbc03034aacd3.tar.gz
scummvm-rg350-f1d9955540076e044905afb3fd6dbc03034aacd3.tar.bz2
scummvm-rg350-f1d9955540076e044905afb3fd6dbc03034aacd3.zip
COMMON: Fix calling Span::getStringAt with non-zero index
-rw-r--r--common/span.h4
-rw-r--r--test/common/span.h2
2 files changed, 4 insertions, 2 deletions
diff --git a/common/span.h b/common/span.h
index 0bb5a25972..2acc0b5fe7 100644
--- a/common/span.h
+++ b/common/span.h
@@ -393,14 +393,14 @@ public:
inline String getStringAt(const index_type index, size_type numEntries = kSpanMaxSize) const {
STATIC_ASSERT(sizeof(value_type) == sizeof(char), strings_can_only_be_read_from_byte_or_char_spans);
- const char *string = (const char *)impl().data();
+ const char *string = (const char *)impl().data() + index;
if (numEntries == kSpanMaxSize) {
numEntries = strnlen(string, impl().size() - index);
}
impl().validate(index, numEntries);
- return String(string + index, numEntries);
+ return String(string, numEntries);
}
/**
diff --git a/test/common/span.h b/test/common/span.h
index d9b1d3120e..55ef2c6bd2 100644
--- a/test/common/span.h
+++ b/test/common/span.h
@@ -496,6 +496,8 @@ public:
TS_ASSERT(span.getStringAt(0) == data);
TS_ASSERT(span.getStringAt(0, 2) == "he");
+ TS_ASSERT(span.getStringAt(2) == "llo");
+ TS_ASSERT(span.getStringAt(2, 3) == "llo");
span[3] = '\0';
TS_ASSERT(span.getStringAt(0) == "hel");
}