From 2250b3c29d3d44b2a8aea73437dcb1bf3a037186 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 8 Mar 2015 12:43:18 -0500 Subject: [PATCH] use Json::RuntimeError --- src/lib_json/json_reader.cpp | 9 ++++----- src/lib_json/json_value.cpp | 4 ++-- src/lib_json/json_writer.cpp | 3 +-- src/test_lib_json/main.cpp | 1 - 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 32f4d02..51cd6a1 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #if defined(_MSC_VER) && _MSC_VER < 1500 // VC++ 8.0 and below #define snprintf _snprintf @@ -148,7 +147,7 @@ bool Reader::readValue() { // But this deprecated class has a security problem: Bad input can // cause a seg-fault. This seems like a fair, binary-compatible way // to prevent the problem. - if (stackDepth_g >= stackLimit_g) throw std::runtime_error("Exceeded stackLimit in readValue()."); + if (stackDepth_g >= stackLimit_g) throwRuntimeError("Exceeded stackLimit in readValue()."); ++stackDepth_g; Token token; @@ -1107,7 +1106,7 @@ bool OurReader::parse(const char* beginDoc, } bool OurReader::readValue() { - if (stackDepth_ >= features_.stackLimit_) throw std::runtime_error("Exceeded stackLimit in readValue()."); + if (stackDepth_ >= features_.stackLimit_) throwRuntimeError("Exceeded stackLimit in readValue()."); ++stackDepth_; Token token; skipCommentTokens(token); @@ -1431,7 +1430,7 @@ bool OurReader::readObject(Token& tokenStart) { return addErrorAndRecover( "Missing ':' after object member name", colon, tokenObjectEnd); } - if (name.length() >= (1U<<30)) throw std::runtime_error("keylength >= 2^30"); + if (name.length() >= (1U<<30)) throwRuntimeError("keylength >= 2^30"); if (features_.rejectDupKeys_ && currentValue().isMember(name)) { std::string msg = "Duplicate key: '" + name + "'"; return addErrorAndRecover( @@ -1994,7 +1993,7 @@ std::istream& operator>>(std::istream& sin, Value& root) { "Error from reader: %s", errs.c_str()); - throw std::runtime_error("reader error"); + throwRuntimeError("reader error"); } return sin; } diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index a71b0c1..bcd2f35 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -88,7 +88,7 @@ static inline char* duplicateStringValue(const char* value, char* newString = static_cast(malloc(length + 1)); if (newString == NULL) { - throw std::runtime_error( + throwRuntimeError( "in Json::Value::duplicateStringValue(): " "Failed to allocate string value buffer"); } @@ -111,7 +111,7 @@ static inline char* duplicateAndPrefixStringValue( unsigned actualLength = length + sizeof(unsigned) + 1U; char* newString = static_cast(malloc(actualLength)); if (newString == 0) { - throw std::runtime_error( + throwRuntimeError( "in Json::Value::duplicateAndPrefixStringValue(): " "Failed to allocate string value buffer"); } diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 69323df..c7f72ee 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -1080,7 +1079,7 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const } else if (cs_str == "None") { cs = CommentStyle::None; } else { - throw std::runtime_error("commentStyle must be 'All' or 'None'"); + throwRuntimeError("commentStyle must be 'All' or 'None'"); } std::string colonSymbol = " : "; if (eyc) { diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index d730444..2b6584e 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -6,7 +6,6 @@ #include "jsontest.h" #include #include -#include #include // Make numeric limits more convenient to talk about.