From 5773e164bb22cb8df965a26671ee00885dfe907d Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 28 Feb 2018 19:59:54 +0100 Subject: [PATCH 1/4] :rotating_light: fixed a linter warning --- .gitignore | 1 + Makefile | 6 ++++++ test/src/unit-readme.cpp | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/.gitignore b/.gitignore index 8157f1a9..35dc9b42 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ fuzz-testing build build_coverage +clang_analyze_build doc/xml doc/html diff --git a/Makefile b/Makefile index 63c9cd78..a873292b 100644 --- a/Makefile +++ b/Makefile @@ -258,6 +258,12 @@ fuzzing-stop: cppcheck: cppcheck --enable=warning --inconclusive --force --std=c++11 $(AMALGAMATED_FILE) --error-exitcode=1 +# compile and check with Clang Static Analyzer +clang_analyze: + rm -fr clang_analyze_build + mkdir clang_analyze_build + cd clang_analyze_build ; CCC_CXX=/Users/niels/Documents/projects/llvm-clang/local/bin/clang++ /Users/niels/Documents/projects/llvm-clang/local/bin/scan-build cmake .. + /Users/niels/Documents/projects/llvm-clang/local/bin/scan-build -enable-checker alpha.core.DynamicTypeChecker,alpha.core.PointerArithm,alpha.core.PointerSub,alpha.cplusplus.DeleteWithNonVirtualDtor,alpha.cplusplus.IteratorRange,alpha.cplusplus.MisusedMovedObject,alpha.security.ArrayBoundV2,alpha.core.Conversion --use-c++=/Users/niels/Documents/projects/llvm-clang/local/bin/clang++ --view -analyze-headers -o clang_analyze_build/report.html make -j10 -C clang_analyze_build ########################################################################## # maintainer targets diff --git a/test/src/unit-readme.cpp b/test/src/unit-readme.cpp index bdcbd73e..05f356a8 100644 --- a/test/src/unit-readme.cpp +++ b/test/src/unit-readme.cpp @@ -168,6 +168,7 @@ TEST_CASE("README", "[hide]") const std::string tmp = j[0]; j[1] = 42; bool foo = j.at(2); + CHECK(foo == true); // other stuff j.size(); // 3 entries @@ -177,6 +178,7 @@ TEST_CASE("README", "[hide]") // comparison bool x = (j == "[\"foo\", 1, true]"_json); // true + CHECK(x == true); // create an object json o; @@ -257,17 +259,21 @@ TEST_CASE("README", "[hide]") bool b1 = true; json jb = b1; bool b2 = jb; + CHECK(b2 == true); // numbers int i = 42; json jn = i; double f = jn; + CHECK(f == 42); // etc. std::string vs = js.get(); bool vb = jb.get(); + CHECK(vb == true); int vi = jn.get(); + CHECK(vi == 42); // etc. } From 8d104e6fe3f2212e165b85ec1a4f9e269406e27e Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 28 Feb 2018 22:40:48 +0100 Subject: [PATCH 2/4] :green_heart: fixed test case --- test/src/unit-readme.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/src/unit-readme.cpp b/test/src/unit-readme.cpp index 05f356a8..45d43879 100644 --- a/test/src/unit-readme.cpp +++ b/test/src/unit-readme.cpp @@ -152,6 +152,10 @@ TEST_CASE("README", "[hide]") j.push_back(1); j.push_back(true); + // comparison + bool x = (j == "[\"foo\", 1, true]"_json); // true + CHECK(x == true); + // iterate the array for (json::iterator it = j.begin(); it != j.end(); ++it) { @@ -176,10 +180,6 @@ TEST_CASE("README", "[hide]") j.type(); // json::value_t::array j.clear(); // the array is empty again - // comparison - bool x = (j == "[\"foo\", 1, true]"_json); // true - CHECK(x == true); - // create an object json o; o["foo"] = 23; From 2a2ed799b1ccc58dc8594770150684a7303fc2d8 Mon Sep 17 00:00:00 2001 From: Mike Bogdanov Date: Fri, 2 Mar 2018 11:12:44 +0300 Subject: [PATCH 3/4] pvs_studio fix. misprinted condition --- include/nlohmann/json.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index f92729f3..591bce33 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -5179,7 +5179,7 @@ class basic_json // passed iterators must belong to objects if (JSON_UNLIKELY(not first.m_object->is_object() - or not first.m_object->is_object())) + or not last.m_object->is_object())) { JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects")); } From fd30ad8a14b9922e4e5849a0364f7546d4755e87 Mon Sep 17 00:00:00 2001 From: Mike Bogdanov Date: Fri, 2 Mar 2018 11:47:35 +0300 Subject: [PATCH 4/4] did make amalgamate --- single_include/nlohmann/json.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 3dcb834b..fb34e18a 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -14777,7 +14777,7 @@ class basic_json // passed iterators must belong to objects if (JSON_UNLIKELY(not first.m_object->is_object() - or not first.m_object->is_object())) + or not last.m_object->is_object())) { JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects")); }