diff --git a/src/str.cpp b/src/str.cpp index b0308ffb..b6ca04d2 100644 --- a/src/str.cpp +++ b/src/str.cpp @@ -266,6 +266,7 @@ int utf8len(unsigned char c, bool suppress){ } int Str::index(const Str& sub, int start) const { + if (start < 0 || start >= this->u8_length()) return -1; auto p = std::search(data + start, data + size, sub.data, sub.data + sub.size); if(p == data + size) return -1; return p - data;