summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-09-26 23:24:04 +0100
committerMaxime Coste <frrrwww@gmail.com>2016-09-26 23:24:09 +0100
commit1e0ec182c166da505ad1404fcbf80240a3797ae4 (patch)
treef766ea9b6361f0dd24f60860a56b2394be0fa6b3 /src
parenta0c20a924acb497ea377367c1e8357afe06063bf (diff)
Assert substr from parameter is within the string
Should catch #756 earlier if it happens again.
Diffstat (limited to 'src')
-rw-r--r--src/string.hh4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/string.hh b/src/string.hh
index 74fbb51a..be140888 100644
--- a/src/string.hh
+++ b/src/string.hh
@@ -231,7 +231,9 @@ inline StringView StringOps<Type, CharType>::substr(ByteCount from, ByteCount le
{
if (length < 0)
length = INT_MAX;
- return StringView{ type().data() + (int)from, std::min(type().length() - from, length) };
+ const auto str_len = type().length();
+ kak_assert(from >= 0 and from <= str_len);
+ return StringView{ type().data() + (int)from, std::min(str_len - from, length) };
}
template<typename Type, typename CharType>