diff --git a/tools/source/misc/json_writer.cxx b/tools/source/misc/json_writer.cxx index e7a0f55fd6c2..3111cac2f816 100644 --- a/tools/source/misc/json_writer.cxx +++ b/tools/source/misc/json_writer.cxx @@ -236,7 +236,8 @@ void JsonWriter::put(std::string_view pPropName, std::string_view rPropVal) ++mPos; // copy and perform escaping - for (size_t i = 0; i < rPropVal.size(); ++i) + bool bReachedEnd = false; + for (size_t i = 0; i < rPropVal.size() && !bReachedEnd; ++i) { char ch = rPropVal[i]; switch (ch) @@ -251,6 +252,9 @@ void JsonWriter::put(std::string_view pPropName, std::string_view rPropVal) case '\\': writeEscapedSequence(ch, mPos); break; + case 0: + bReachedEnd = true; + break; case '\xE2': // Special processing of U+2028 and U+2029 if (i + 2 < rPropVal.size() && rPropVal[i + 1] == '\x80' && (rPropVal[i + 2] == '\xA8' || rPropVal[i + 2] == '\xA9'))