summaryrefslogtreecommitdiff
path: root/src/string.hh
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-04-20 12:03:57 +0100
committerMaxime Coste <frrrwww@gmail.com>2014-04-20 12:03:57 +0100
commitc4295b7e30d5fe9527fd7f3a20bc12ccfca8b94c (patch)
tree20a40ac72fa479c57bb419e05025373fc6dc738e /src/string.hh
parent055eacd032d80f9359f1a05afe48d126bb5ccd3b (diff)
Fix StringView::substr when passed a negative length
Diffstat (limited to 'src/string.hh')
-rw-r--r--src/string.hh4
1 files changed, 4 insertions, 0 deletions
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) };
}