From c8e1480593110872fdc9682bc8b822b82383ec7b Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 22 Jun 2014 15:03:26 +0000 Subject: [PATCH] base: allow String::Sub to ask for a too large substring. --- src/lol/base/string.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lol/base/string.h b/src/lol/base/string.h index b66b82cd..0d0bd51e 100644 --- a/src/lol/base/string.h +++ b/src/lol/base/string.h @@ -115,11 +115,13 @@ public: ((Super &)*this).Last() = '\0'; } - String Sub(int start, int count) const + String Sub(int start, int count = -1) const { ASSERT(start >= 0); - ASSERT(count >= 0); - ASSERT(start + count <= Count()); + if (start >= Count()) + return String(); + if (count < 0 || count >= Count() - start) + count = Count() - start; return String(&(*this)[start], count); }