From c4295b7e30d5fe9527fd7f3a20bc12ccfca8b94c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 20 Apr 2014 12:03:57 +0100 Subject: [PATCH] Fix StringView::substr when passed a negative length --- src/string.hh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/string.hh b/src/string.hh index 8dd51404..5e0446e2 100644 --- a/src/string.hh +++ b/src/string.hh @@ -150,11 +150,15 @@ inline CharCount StringView::char_count_to(ByteCount count) const inline StringView StringView::substr(ByteCount from, ByteCount length) const { + if (length < 0) + length = INT_MAX; return StringView{ m_data + (int)from, std::min(m_length - from, length) }; } inline StringView StringView::substr(CharCount from, CharCount length) const { + if (length < 0) + length = INT_MAX; auto beg = utf8::advance(begin(), end(), (int)from); return StringView{ beg, utf8::advance(beg, end(), length) }; }