diff --git a/src/ini_load.cpp b/src/ini_load.cpp index 564a3b8ffe..aced34b3a7 100644 --- a/src/ini_load.cpp +++ b/src/ini_load.cpp @@ -290,7 +290,7 @@ void IniLoadFile::LoadFromDisk(const std::string &filename, Subdirectory subdir, if (!quoted && e == t) { item.value.reset(); } else { - item.value = StrMakeValid(std::string(t)); + item.value = StrMakeValid(std::string_view(t)); } } else { /* it's an orphan item */ diff --git a/src/string.cpp b/src/string.cpp index 830f37e962..f1b732a6ab 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -268,7 +268,7 @@ static void StrMakeValid(T &dst, const char *str, const char *last, StringValida * would also reach the "last" byte of the string and a normal '\0' * termination will be placed after it. */ - if (len == 0 || str + len > last || len != Utf8Decode(&c, str)) { + if (len == 0 || str + len > last + 1 || len != Utf8Decode(&c, str)) { /* Maybe the next byte is still a valid character? */ str++; continue; @@ -341,7 +341,7 @@ void StrMakeValidInPlace(char *str, StringValidationSettings settings) std::string StrMakeValid(std::string_view str, StringValidationSettings settings) { auto buf = str.data(); - auto last = buf + str.size(); + auto last = buf + str.size() - 1; std::ostringstream dst; std::ostreambuf_iterator dst_iter(dst);