mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-12 10:03:51 +01:00
clang-tidy fixes again (#1087)
* [clang-tidy] Do not use else after return Found with readability-else-after-return Signed-off-by: Rosen Penev <rosenp@gmail.com> * [clang-tidy] Convert several loops to be range based Found with modernize-loop-convert Signed-off-by: Rosen Penev <rosenp@gmail.com> * [clang-tidy] Replace deprecated C headers Found with modernize-deprecated-headers Signed-off-by: Rosen Penev <rosenp@gmail.com> * [clang-tidy] Use auto where applicable Found with modernize-use-auto Signed-off-by: Rosen Penev <rosenp@gmail.com> * .clang-tidy: Add these checks
This commit is contained in:
parent
6317f9a406
commit
edf528edfa
@ -1,5 +1,5 @@
|
||||
---
|
||||
Checks: 'google-readability-casting,modernize-use-default-member-init,modernize-use-using,modernize-use-auto,readability-redundant-member-init'
|
||||
Checks: 'google-readability-casting,modernize-deprecated-headers,modernize-loop-convert,modernize-use-auto,modernize-use-default-member-init,modernize-use-using,readability-else-after-return,readability-redundant-member-init,readability-redundant-string-cstr'
|
||||
WarningsAsErrors: ''
|
||||
HeaderFilterRegex: ''
|
||||
AnalyzeTemporaryDtors: false
|
||||
|
@ -57,10 +57,10 @@ static Json::String readInputTestFile(const char* path) {
|
||||
if (!file)
|
||||
return "";
|
||||
fseek(file, 0, SEEK_END);
|
||||
long const size = ftell(file);
|
||||
const auto usize = static_cast<size_t>(size);
|
||||
auto const size = ftell(file);
|
||||
auto const usize = static_cast<size_t>(size);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
char* buffer = new char[size + 1];
|
||||
auto buffer = new char[size + 1];
|
||||
buffer[size] = 0;
|
||||
Json::String text;
|
||||
if (fread(buffer, 1, usize, file) == usize)
|
||||
|
@ -637,7 +637,7 @@ bool Reader::decodeString(Token& token, String& decoded) {
|
||||
Char c = *current++;
|
||||
if (c == '"')
|
||||
break;
|
||||
else if (c == '\\') {
|
||||
if (c == '\\') {
|
||||
if (current == end)
|
||||
return addError("Empty escape sequence in string", token, current);
|
||||
Char escape = *current++;
|
||||
@ -1358,11 +1358,10 @@ bool OurReader::readCStyleComment(bool* containsNewLineResult) {
|
||||
|
||||
while ((current_ + 1) < end_) {
|
||||
Char c = getNextChar();
|
||||
if (c == '*' && *current_ == '/') {
|
||||
if (c == '*' && *current_ == '/')
|
||||
break;
|
||||
} else if (c == '\n') {
|
||||
if (c == '\n')
|
||||
*containsNewLineResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
return getNextChar() == '/';
|
||||
@ -1586,9 +1585,9 @@ bool OurReader::decodeNumber(Token& token, Value& decoded) {
|
||||
// then take the inverse. This assumes that minLargestInt is only a single
|
||||
// power of 10 different in magnitude, which we check above. For the last
|
||||
// digit, we take the modulus before negating for the same reason.
|
||||
static constexpr Value::LargestUInt negative_threshold =
|
||||
static constexpr auto negative_threshold =
|
||||
Value::LargestUInt(-(Value::minLargestInt / 10));
|
||||
static constexpr Value::UInt negative_last_digit =
|
||||
static constexpr auto negative_last_digit =
|
||||
Value::UInt(-(Value::minLargestInt % 10));
|
||||
|
||||
const Value::LargestUInt threshold =
|
||||
@ -1602,7 +1601,7 @@ bool OurReader::decodeNumber(Token& token, Value& decoded) {
|
||||
if (c < '0' || c > '9')
|
||||
return decodeDouble(token, decoded);
|
||||
|
||||
const Value::UInt digit(static_cast<Value::UInt>(c - '0'));
|
||||
const auto digit(static_cast<Value::UInt>(c - '0'));
|
||||
if (value >= threshold) {
|
||||
// We've hit or exceeded the max value divided by 10 (rounded down). If
|
||||
// a) we've only just touched the limit, meaing value == threshold,
|
||||
@ -1619,7 +1618,7 @@ bool OurReader::decodeNumber(Token& token, Value& decoded) {
|
||||
|
||||
if (isNegative) {
|
||||
// We use the same magnitude assumption here, just in case.
|
||||
const Value::UInt last_digit = static_cast<Value::UInt>(value % 10);
|
||||
const auto last_digit = static_cast<Value::UInt>(value % 10);
|
||||
decoded = -Value::LargestInt(value / 10) * 10 - last_digit;
|
||||
} else if (value <= Value::LargestUInt(Value::maxLargestInt)) {
|
||||
decoded = Value::LargestInt(value);
|
||||
@ -1669,9 +1668,9 @@ bool OurReader::decodeString(Token& token, String& decoded) {
|
||||
Location end = token.end_ - 1; // do not include '"'
|
||||
while (current != end) {
|
||||
Char c = *current++;
|
||||
if (c == '"') {
|
||||
if (c == '"')
|
||||
break;
|
||||
} else if (c == '\\') {
|
||||
if (c == '\\') {
|
||||
if (current == end)
|
||||
return addError("Empty escape sequence in string", token, current);
|
||||
Char escape = *current++;
|
||||
|
@ -875,8 +875,7 @@ ArrayIndex Value::size() const {
|
||||
bool Value::empty() const {
|
||||
if (isNull() || isArray() || isObject())
|
||||
return size() == 0U;
|
||||
else
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
Value::operator bool() const { return !isNull(); }
|
||||
@ -1137,13 +1136,12 @@ bool Value::insert(ArrayIndex index, Value&& newValue) {
|
||||
ArrayIndex length = size();
|
||||
if (index > length) {
|
||||
return false;
|
||||
} else {
|
||||
for (ArrayIndex i = length; i > index; i--) {
|
||||
(*this)[i] = std::move((*this)[i - 1]);
|
||||
}
|
||||
(*this)[index] = std::move(newValue);
|
||||
return true;
|
||||
}
|
||||
for (ArrayIndex i = length; i > index; i--) {
|
||||
(*this)[i] = std::move((*this)[i - 1]);
|
||||
}
|
||||
(*this)[index] = std::move(newValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
Value Value::get(char const* begin, char const* end,
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include <json/config.h>
|
||||
#include <json/json.h>
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
namespace Json {
|
||||
|
@ -267,19 +267,18 @@ bool Runner::runAllTest(bool printSummary) const {
|
||||
printf("All %zu tests passed\n", count);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
for (auto& result : failures) {
|
||||
result.printFailure(count > 1);
|
||||
}
|
||||
|
||||
if (printSummary) {
|
||||
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;
|
||||
}
|
||||
for (auto& result : failures) {
|
||||
result.printFailure(count > 1);
|
||||
}
|
||||
|
||||
if (printSummary) {
|
||||
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 Json::String& testName, size_t& indexOut) const {
|
||||
@ -308,7 +307,8 @@ int Runner::runCommandLine(int argc, const char* argv[]) const {
|
||||
if (opt == "--list-tests") {
|
||||
listTests();
|
||||
return 0;
|
||||
} else if (opt == "--test-auto") {
|
||||
}
|
||||
if (opt == "--test-auto") {
|
||||
preventDialogOnCrash();
|
||||
} else if (opt == "--test") {
|
||||
++index;
|
||||
|
@ -1476,9 +1476,7 @@ void ValueTest::checkMemberCount(Json::Value& value,
|
||||
JSONTEST_ASSERT_PRED(checkConstMemberCount(value, expectedCount));
|
||||
}
|
||||
|
||||
ValueTest::IsCheck::IsCheck()
|
||||
|
||||
= default;
|
||||
ValueTest::IsCheck::IsCheck() = default;
|
||||
|
||||
void ValueTest::checkIs(const Json::Value& value, const IsCheck& check) {
|
||||
JSONTEST_ASSERT_EQUAL(check.isObject_, value.isObject());
|
||||
@ -3752,8 +3750,8 @@ JSONTEST_FIXTURE_LOCAL(FuzzTest, fuzzDoesntCrash) {
|
||||
int main(int argc, const char* argv[]) {
|
||||
JsonTest::Runner runner;
|
||||
|
||||
for (auto it = local_.begin(); it != local_.end(); it++) {
|
||||
runner.add(*it);
|
||||
for (auto& local : local_) {
|
||||
runner.add(local);
|
||||
}
|
||||
|
||||
return runner.runCommandLine(argc, argv);
|
||||
|
Loading…
Reference in New Issue
Block a user