STYLE: Avoid unnecessary conversions from size_t to unsigned int
Make the index values consistent with size_t.
diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp
index fc6b139..56acc6a 100644
--- a/src/lib_json/json_reader.cpp
+++ b/src/lib_json/json_reader.cpp
@@ -888,7 +888,7 @@
bool failIfExtra_;
bool rejectDupKeys_;
bool allowSpecialFloats_;
- int stackLimit_;
+ size_t stackLimit_;
}; // OurFeatures
// exact copy of Implementation of class Features
@@ -1087,7 +1087,7 @@
bool OurReader::readValue() {
// To preserve the old behaviour we cast size_t to int.
- if (static_cast<int>(nodes_.size()) > features_.stackLimit_)
+ if (nodes_.size() > features_.stackLimit_)
throwRuntimeError("Exceeded stackLimit in readValue().");
Token token;
skipCommentTokens(token);
@@ -1917,7 +1917,11 @@
settings_["allowDroppedNullPlaceholders"].asBool();
features.allowNumericKeys_ = settings_["allowNumericKeys"].asBool();
features.allowSingleQuotes_ = settings_["allowSingleQuotes"].asBool();
- features.stackLimit_ = settings_["stackLimit"].asInt();
+#if defined(JSON_HAS_INT64)
+ features.stackLimit_ = settings_["stackLimit"].asUInt64();
+#else
+ features.stackLimit_ = settings_["stackLimit"].asUInt();
+#endif
features.failIfExtra_ = settings_["failIfExtra"].asBool();
features.rejectDupKeys_ = settings_["rejectDupKeys"].asBool();
features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool();
diff --git a/src/test_lib_json/jsontest.cpp b/src/test_lib_json/jsontest.cpp
index 369ca9f..1545e03 100644
--- a/src/test_lib_json/jsontest.cpp
+++ b/src/test_lib_json/jsontest.cpp
@@ -224,18 +224,18 @@
return *this;
}
-unsigned int Runner::testCount() const {
- return static_cast<unsigned int>(tests_.size());
+size_t Runner::testCount() const {
+ return tests_.size();
}
-JSONCPP_STRING Runner::testNameAt(unsigned int index) const {
+JSONCPP_STRING Runner::testNameAt(size_t index) const {
TestCase* test = tests_[index]();
JSONCPP_STRING name = test->testName();
delete test;
return name;
}
-void Runner::runTestAt(unsigned int index, TestResult& result) const {
+void Runner::runTestAt(size_t index, TestResult& result) const {
TestCase* test = tests_[index]();
result.setTestName(test->testName());
printf("Testing %s: ", test->testName());
@@ -257,9 +257,9 @@
}
bool Runner::runAllTest(bool printSummary) const {
- unsigned int count = testCount();
+ size_t const count = testCount();
std::deque<TestResult> failures;
- for (unsigned int index = 0; index < count; ++index) {
+ for (size_t index = 0; index < count; ++index) {
TestResult result;
runTestAt(index, result);
if (result.failed()) {
@@ -269,7 +269,7 @@
if (failures.empty()) {
if (printSummary) {
- printf("All %u tests passed\n", count);
+ printf("All %zu tests passed\n", count);
}
return true;
} else {
@@ -278,19 +278,19 @@
}
if (printSummary) {
- auto failedCount = static_cast<unsigned int>(failures.size());
- unsigned int passedCount = count - failedCount;
- printf("%u/%u tests passed (%u failure(s))\n", passedCount, count,
- failedCount);
+ size_t const failedCount = failures.size();
+ size_t const passedCount = count - failedCount;
+ printf("%zu/%zu tests passed (%zu failure(s))\n",
+ passedCount, count, failedCount);
}
return false;
}
}
bool Runner::testIndex(const JSONCPP_STRING& testName,
- unsigned int& indexOut) const {
- unsigned int count = testCount();
- for (unsigned int index = 0; index < count; ++index) {
+ size_t& indexOut) const {
+ const size_t count = testCount();
+ for (size_t index = 0; index < count; ++index) {
if (testNameAt(index) == testName) {
indexOut = index;
return true;
@@ -300,8 +300,8 @@
}
void Runner::listTests() const {
- unsigned int count = testCount();
- for (unsigned int index = 0; index < count; ++index) {
+ const size_t count = testCount();
+ for (size_t index = 0; index < count; ++index) {
printf("%s\n", testNameAt(index).c_str());
}
}
@@ -319,7 +319,7 @@
} else if (opt == "--test") {
++index;
if (index < argc) {
- unsigned int testNameIndex;
+ size_t testNameIndex;
if (testIndex(argv[index], testNameIndex)) {
subrunner.add(tests_[testNameIndex]);
} else {
diff --git a/src/test_lib_json/jsontest.h b/src/test_lib_json/jsontest.h
index 85952a5..57d42ba 100644
--- a/src/test_lib_json/jsontest.h
+++ b/src/test_lib_json/jsontest.h
@@ -151,13 +151,13 @@
bool runAllTest(bool printSummary) const;
/// Returns the number of test case in the suite
- unsigned int testCount() const;
+ size_t testCount() const;
/// Returns the name of the test case at the specified index
- JSONCPP_STRING testNameAt(unsigned int index) const;
+ JSONCPP_STRING testNameAt(size_t index) const;
/// Runs the test case at the specified index using the specified TestResult
- void runTestAt(unsigned int index, TestResult& result) const;
+ void runTestAt(size_t index, TestResult& result) const;
static void printUsage(const char* appName);
@@ -167,7 +167,7 @@
private:
void listTests() const;
- bool testIndex(const JSONCPP_STRING& testName, unsigned int& indexOut) const;
+ bool testIndex(const JSONCPP_STRING& testName, size_t& indexOut) const;
static void preventDialogOnCrash();
private: