Skip to content

Commit

Permalink
Improve error handling in JSON when NUL letter is encountered
Browse files Browse the repository at this point in the history
  • Loading branch information
hcho3 committed Jun 27, 2020
1 parent 6810799 commit 5a5f99c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions include/xgboost/json_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
#include <vector>
#include <memory>
#include <string>
#include <cinttypes>
#include <utility>
#include <map>
#include <limits>
#include <sstream>
#include <locale>
#include <cinttypes>
#include <cstdio>

namespace xgboost {
/*
Expand Down Expand Up @@ -84,8 +85,10 @@ class JsonReader {
std::string msg = "Expecting: \"";
msg += c;
msg += "\", got: \"";
if (got == -1) {
if (got == EOF) {
msg += "EOF\"";
} else if (got == 0) {
msg += "\\0\"";
} else {
msg += std::to_string(got) + " \"";
}
Expand Down
2 changes: 2 additions & 0 deletions src/common/json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ void JsonReader::Error(std::string msg) const {
for (auto c : raw_portion) {
if (c == '\n') {
portion += "\\n";
} else if (c == '\0') {
portion += "\\0";
} else {
portion += c;
}
Expand Down

0 comments on commit 5a5f99c

Please sign in to comment.