From e3a2be376784ddb8636e488a3003c52b22d79060 Mon Sep 17 00:00:00 2001 From: fangyunzhong Date: Sat, 7 Jan 2023 02:05:44 +0000 Subject: [PATCH] Add boundary check to avoid cross the border Signed-off-by: fangyunzhong --- src/lib_json/json_reader.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index a921dfe..cf3ec48 100755 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -772,6 +772,10 @@ void Reader::getLocationLineAndColumn(Location location, int& line, while (current < location && current != end_) { Char c = *current++; if (c == '\r') { + // Add boundary check to avoid cross the border + if (current == end_) { + break; + } if (*current == '\n') ++current; lastLineStart = current; @@ -1838,6 +1842,10 @@ void OurReader::getLocationLineAndColumn(Location location, int& line, while (current < location && current != end_) { Char c = *current++; if (c == '\r') { + // Add boundary check to avoid cross the border + if (current == end_) { + break; + } if (*current == '\n') ++current; lastLineStart = current; -- Gitee