Skip to content

Commit 2250b3c

Browse files
committed
use Json::RuntimeError
1 parent 9376368 commit 2250b3c

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

src/lib_json/json_reader.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <sstream>
1818
#include <memory>
1919
#include <set>
20-
#include <stdexcept>
2120

2221
#if defined(_MSC_VER) && _MSC_VER < 1500 // VC++ 8.0 and below
2322
#define snprintf _snprintf
@@ -148,7 +147,7 @@ bool Reader::readValue() {
148147
// But this deprecated class has a security problem: Bad input can
149148
// cause a seg-fault. This seems like a fair, binary-compatible way
150149
// to prevent the problem.
151-
if (stackDepth_g >= stackLimit_g) throw std::runtime_error("Exceeded stackLimit in readValue().");
150+
if (stackDepth_g >= stackLimit_g) throwRuntimeError("Exceeded stackLimit in readValue().");
152151
++stackDepth_g;
153152

154153
Token token;
@@ -1107,7 +1106,7 @@ bool OurReader::parse(const char* beginDoc,
11071106
}
11081107

11091108
bool OurReader::readValue() {
1110-
if (stackDepth_ >= features_.stackLimit_) throw std::runtime_error("Exceeded stackLimit in readValue().");
1109+
if (stackDepth_ >= features_.stackLimit_) throwRuntimeError("Exceeded stackLimit in readValue().");
11111110
++stackDepth_;
11121111
Token token;
11131112
skipCommentTokens(token);
@@ -1431,7 +1430,7 @@ bool OurReader::readObject(Token& tokenStart) {
14311430
return addErrorAndRecover(
14321431
"Missing ':' after object member name", colon, tokenObjectEnd);
14331432
}
1434-
if (name.length() >= (1U<<30)) throw std::runtime_error("keylength >= 2^30");
1433+
if (name.length() >= (1U<<30)) throwRuntimeError("keylength >= 2^30");
14351434
if (features_.rejectDupKeys_ && currentValue().isMember(name)) {
14361435
std::string msg = "Duplicate key: '" + name + "'";
14371436
return addErrorAndRecover(
@@ -1994,7 +1993,7 @@ std::istream& operator>>(std::istream& sin, Value& root) {
19941993
"Error from reader: %s",
19951994
errs.c_str());
19961995

1997-
throw std::runtime_error("reader error");
1996+
throwRuntimeError("reader error");
19981997
}
19991998
return sin;
20001999
}

src/lib_json/json_value.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static inline char* duplicateStringValue(const char* value,
8888

8989
char* newString = static_cast<char*>(malloc(length + 1));
9090
if (newString == NULL) {
91-
throw std::runtime_error(
91+
throwRuntimeError(
9292
"in Json::Value::duplicateStringValue(): "
9393
"Failed to allocate string value buffer");
9494
}
@@ -111,7 +111,7 @@ static inline char* duplicateAndPrefixStringValue(
111111
unsigned actualLength = length + sizeof(unsigned) + 1U;
112112
char* newString = static_cast<char*>(malloc(actualLength));
113113
if (newString == 0) {
114-
throw std::runtime_error(
114+
throwRuntimeError(
115115
"in Json::Value::duplicateAndPrefixStringValue(): "
116116
"Failed to allocate string value buffer");
117117
}

src/lib_json/json_writer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <sstream>
1313
#include <utility>
1414
#include <set>
15-
#include <stdexcept>
1615
#include <assert.h>
1716
#include <math.h>
1817
#include <stdio.h>
@@ -1080,7 +1079,7 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const
10801079
} else if (cs_str == "None") {
10811080
cs = CommentStyle::None;
10821081
} else {
1083-
throw std::runtime_error("commentStyle must be 'All' or 'None'");
1082+
throwRuntimeError("commentStyle must be 'All' or 'None'");
10841083
}
10851084
std::string colonSymbol = " : ";
10861085
if (eyc) {

src/test_lib_json/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "jsontest.h"
77
#include <json/config.h>
88
#include <json/json.h>
9-
#include <stdexcept>
109
#include <cstring>
1110

1211
// Make numeric limits more convenient to talk about.

0 commit comments

Comments
 (0)