diff --git a/.travis.yml b/.travis.yml index ad1d12d97..bd806cb89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,6 +41,20 @@ matrix: after_success: - valgrind --error-exitcode=1 --leak-check=full test/json_unit + # cppcheck + + - os: linux + compiler: gcc + env: + - COMPILER=g++-4.9 + - SPECIAL=cppcheck + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: [g++-4.9, cppcheck] + after_success: + - make cppcheck + # Coveralls (http://gronlier.fr/blog/2015/01/adding-code-coverage-to-your-c-project/) - os: linux diff --git a/Makefile b/Makefile index f08d5cf37..b53d8d3dc 100644 --- a/Makefile +++ b/Makefile @@ -64,8 +64,7 @@ fuzz: test/src/fuzz.cpp src/json.hpp # call cppcheck on the main header file cppcheck: - cppcheck --enable=all --inconclusive --std=c++11 src/json.hpp - + cppcheck --enable=warning --inconclusive --force --std=c++11 src/json.hpp --error-exitcode=1 ########################################################################## # maintainer targets diff --git a/README.md b/README.md index 73a03363b..3015e860a 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ There are myriads of [JSON](http://json.org) libraries out there, and each may e - **Trivial integration**. Our whole code consists of a single header file [`json.hpp`](https://github.com/nlohmann/json/blob/develop/src/json.hpp). That's it. No library, no subproject, no dependencies, no complex build system. The class is written in vanilla C++11. All in all, everything should require no adjustment of your compiler flags or project settings. -- **Serious testing**. Our class is heavily [unit-tested](https://github.com/nlohmann/json/blob/master/test/src/unit.cpp) and covers [100%](https://coveralls.io/r/nlohmann/json) of the code, including all exceptional behavior. Furthermore, we checked with [Valgrind](http://valgrind.org) that there are no memory leaks. +- **Serious testing**. Our class is heavily [unit-tested](https://github.com/nlohmann/json/blob/master/test/src/unit.cpp) and covers [100%](https://coveralls.io/r/nlohmann/json) of the code, including all exceptional behavior. Furthermore, we checked with [Valgrind](http://valgrind.org) that there are no memory leaks. To maintain high quality, the project is following the [Core Infrastructure Initiative (CII) best practices](https://bestpractices.coreinfrastructure.org/projects/289). Other aspects were not so important to us: diff --git a/src/json.hpp b/src/json.hpp index 6bafd0072..f10e5960a 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -9009,7 +9009,8 @@ basic_json_parser_63: { case lexer::token_type::begin_object: { - if (keep and (not callback or (keep = callback(depth++, parse_event_t::object_start, result)))) + if (keep and (not callback + or ((keep = callback(depth++, parse_event_t::object_start, result)) != 0))) { // explicitly set result to object to cope with {} result.m_type = value_t::object; @@ -9087,7 +9088,8 @@ basic_json_parser_63: case lexer::token_type::begin_array: { - if (keep and (not callback or (keep = callback(depth++, parse_event_t::array_start, result)))) + if (keep and (not callback + or ((keep = callback(depth++, parse_event_t::array_start, result)) != 0))) { // explicitly set result to object to cope with [] result.m_type = value_t::array; diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 87f7aabcf..b1f5a6334 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -8306,7 +8306,8 @@ class basic_json { case lexer::token_type::begin_object: { - if (keep and (not callback or (keep = callback(depth++, parse_event_t::object_start, result)))) + if (keep and (not callback + or ((keep = callback(depth++, parse_event_t::object_start, result)) != 0))) { // explicitly set result to object to cope with {} result.m_type = value_t::object; @@ -8384,7 +8385,8 @@ class basic_json case lexer::token_type::begin_array: { - if (keep and (not callback or (keep = callback(depth++, parse_event_t::array_start, result)))) + if (keep and (not callback + or ((keep = callback(depth++, parse_event_t::array_start, result)) != 0))) { // explicitly set result to object to cope with [] result.m_type = value_t::array;