diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-09-26 23:24:04 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-09-26 23:24:09 +0100 |
| commit | 1e0ec182c166da505ad1404fcbf80240a3797ae4 (patch) | |
| tree | f766ea9b6361f0dd24f60860a56b2394be0fa6b3 /src/string.hh | |
| parent | a0c20a924acb497ea377367c1e8357afe06063bf (diff) | |
Assert substr from parameter is within the string
Should catch #756 earlier if it happens again.
Diffstat (limited to 'src/string.hh')
| -rw-r--r-- | src/string.hh | 4 |
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> |
