From 1e0ec182c166da505ad1404fcbf80240a3797ae4 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 26 Sep 2016 23:24:04 +0100 Subject: [PATCH] Assert substr from parameter is within the string Should catch #756 earlier if it happens again. --- src/string.hh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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::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