diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2014-04-20 12:03:57 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2014-04-20 12:03:57 +0100 |
| commit | c4295b7e30d5fe9527fd7f3a20bc12ccfca8b94c (patch) | |
| tree | 20a40ac72fa479c57bb419e05025373fc6dc738e /src/string.hh | |
| parent | 055eacd032d80f9359f1a05afe48d126bb5ccd3b (diff) | |
Fix StringView::substr when passed a negative length
Diffstat (limited to 'src/string.hh')
| -rw-r--r-- | src/string.hh | 4 |
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) }; } |
