Merge branch 'pvs-studio-fix-05-09-2020' of https://github.com/pavel-pimenov/jsoncpp into pvs-studio-fix-05-09-2020

This commit is contained in:
Pave Pimenov 2020-11-07 22:07:17 +03:00
commit 82da440ea1
18 changed files with 108 additions and 39 deletions

View File

@ -22,8 +22,6 @@ addons:
- clang-8 - clang-8
- valgrind - valgrind
matrix: matrix:
allow_failures:
- os: osx
include: include:
- name: Mac clang meson static release testing - name: Mac clang meson static release testing
os: osx os: osx
@ -44,6 +42,8 @@ matrix:
CC="clang" CC="clang"
LIB_TYPE=static LIB_TYPE=static
BUILD_TYPE=release BUILD_TYPE=release
PYTHONUSERBASE="$(pwd)/LOCAL"
PATH="$PYTHONUSERBASE/bin:$PATH"
# before_install and install steps only needed for linux meson builds # before_install and install steps only needed for linux meson builds
before_install: before_install:
- source ./.travis_scripts/travis.before_install.${TRAVIS_OS_NAME}.sh - source ./.travis_scripts/travis.before_install.${TRAVIS_OS_NAME}.sh

View File

@ -1 +0,0 @@
# NOTHING TO DO HERE

View File

@ -1,10 +1,5 @@
set -vex set -vex
wget https://github.com/ninja-build/ninja/releases/download/v1.9.0/ninja-linux.zip pip3 install --user meson ninja
unzip -q ninja-linux.zip -d build which meson
which ninja
pip3 install meson
echo ${PATH}
ls /usr/local
ls /usr/local/bin
export PATH="${PWD}"/build:/usr/local/bin:/usr/bin:${PATH}

View File

@ -69,12 +69,15 @@ project(jsoncpp
# 2. ./include/json/version.h # 2. ./include/json/version.h
# 3. ./CMakeLists.txt # 3. ./CMakeLists.txt
# IMPORTANT: also update the PROJECT_SOVERSION!! # IMPORTANT: also update the PROJECT_SOVERSION!!
VERSION 1.9.3 # <major>[.<minor>[.<patch>[.<tweak>]]] VERSION 1.9.4 # <major>[.<minor>[.<patch>[.<tweak>]]]
LANGUAGES CXX) LANGUAGES CXX)
message(STATUS "JsonCpp Version: ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") message(STATUS "JsonCpp Version: ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
set(PROJECT_SOVERSION 24) set(PROJECT_SOVERSION 24)
include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInSourceBuilds.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInBuildInstalls.cmake)
option(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON) option(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON)
option(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON) option(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON)
option(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF) option(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF)

View File

@ -19,7 +19,7 @@ If you wish to install to a directory other than /usr/local, set an environment
DESTDIR=/path/to/install/dir DESTDIR=/path/to/install/dir
Then, Then,
```sh
cd jsoncpp/ cd jsoncpp/
BUILD_TYPE=debug BUILD_TYPE=debug
#BUILD_TYPE=release #BUILD_TYPE=release
@ -35,6 +35,7 @@ Then,
#meson test --no-rebuild --print-errorlogs #meson test --no-rebuild --print-errorlogs
sudo ninja install sudo ninja install
```
## Building and testing with other build systems ## Building and testing with other build systems
See https://github.com/open-source-parsers/jsoncpp/wiki/Building See https://github.com/open-source-parsers/jsoncpp/wiki/Building
@ -143,7 +144,9 @@ bool Reader::decodeNumber(Token& token) {
``` ```
Before submitting your code, ensure that you meet the versioning requirements above, follow the style guide of the file you are modifying (or the above rules for new files), and run clang format. Meson exposes clang format with the following command: Before submitting your code, ensure that you meet the versioning requirements above, follow the style guide of the file you are modifying (or the above rules for new files), and run clang format. Meson exposes clang format with the following command:
``` ```
ninja -v -C build-${LIB_TYPE}/ clang-format ninja -v -C build-${LIB_TYPE}/ clang-format
``` ```
For convenience, you can also run the `reformat.sh` script located in the root directory.

View File

@ -1,6 +1,7 @@
clone_folder: c:\projects\jsoncpp clone_folder: c:\projects\jsoncpp
environment: environment:
matrix: matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
CMAKE_GENERATOR: Visual Studio 14 2015 CMAKE_GENERATOR: Visual Studio 14 2015
@ -13,11 +14,15 @@ environment:
build_script: build_script:
- cmake --version - cmake --version
- cd c:\projects\jsoncpp # The build script starts in root.
- cmake -G "%CMAKE_GENERATOR%" -DCMAKE_INSTALL_PREFIX:PATH=%CD:\=/%/install -DBUILD_SHARED_LIBS:BOOL=ON . - set JSONCPP_FOLDER=%cd%
- set JSONCPP_BUILD_FOLDER=%JSONCPP_FOLDER%\build\release
- mkdir -p %JSONCPP_BUILD_FOLDER%
- cd %JSONCPP_BUILD_FOLDER%
- cmake -G "%CMAKE_GENERATOR%" -DCMAKE_INSTALL_PREFIX:PATH=%CD:\=/%/install -DBUILD_SHARED_LIBS:BOOL=ON %JSONCPP_FOLDER%
# Use ctest to make a dashboard build: # Use ctest to make a dashboard build:
# - ctest -D Experimental(Start|Update|Configure|Build|Test|Coverage|MemCheck|Submit) # - ctest -D Experimental(Start|Update|Configure|Build|Test|Coverage|MemCheck|Submit)
# NOTE: Testing on window is not yet finished: # NOTE: Testing on windows is not yet finished:
# - ctest -C Release -D ExperimentalStart -D ExperimentalConfigure -D ExperimentalBuild -D ExperimentalTest -D ExperimentalSubmit # - ctest -C Release -D ExperimentalStart -D ExperimentalConfigure -D ExperimentalBuild -D ExperimentalTest -D ExperimentalSubmit
- ctest -C Release -D ExperimentalStart -D ExperimentalConfigure -D ExperimentalBuild -D ExperimentalSubmit - ctest -C Release -D ExperimentalStart -D ExperimentalConfigure -D ExperimentalBuild -D ExperimentalSubmit
# Final step is to verify that installation succeeds # Final step is to verify that installation succeeds

View File

@ -0,0 +1,9 @@
string(TOLOWER "${CMAKE_INSTALL_PREFIX}" _PREFIX)
string(TOLOWER "${ITK_BINARY_DIR}" _BUILD)
if("${_PREFIX}" STREQUAL "${_BUILD}")
message(FATAL_ERROR
"The current CMAKE_INSTALL_PREFIX points at the build tree:\n"
" ${CMAKE_INSTALL_PREFIX}\n"
"This is not supported."
)
endif()

View File

@ -0,0 +1,45 @@
#
# This function will prevent in-source builds
function(AssureOutOfSourceBuilds)
# make sure the user doesn't play dirty with symlinks
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
# disallow in-source builds
if("${srcdir}" STREQUAL "${bindir}")
message("######################################################")
message("# jsoncpp should not be configured & built in the jsoncpp source directory")
message("# You must run cmake in a build directory.")
message("# For example:")
message("# mkdir jsoncpp-Sandbox ; cd jsoncpp-sandbox")
message("# git clone https://github.com/open-source-parsers/jsoncpp.git # or download & unpack the source tarball")
message("# mkdir jsoncpp-build")
message("# this will create the following directory structure")
message("#")
message("# jsoncpp-Sandbox")
message("# +--jsoncpp")
message("# +--jsoncpp-build")
message("#")
message("# Then you can proceed to configure and build")
message("# by using the following commands")
message("#")
message("# cd jsoncpp-build")
message("# cmake ../jsoncpp # or ccmake, or cmake-gui ")
message("# make")
message("#")
message("# NOTE: Given that you already tried to make an in-source build")
message("# CMake have already created several files & directories")
message("# in your source tree. run 'git status' to find them and")
message("# remove them by doing:")
message("#")
message("# cd jsoncpp-Sandbox/jsoncpp")
message("# git clean -n -d")
message("# git clean -f -d")
message("# git checkout --")
message("#")
message("######################################################")
message(FATAL_ERROR "Quitting configuration")
endif()
endfunction()
AssureOutOfSourceBuilds()

View File

@ -35,11 +35,10 @@ public:
* Release memory which was allocated for N items at pointer P. * Release memory which was allocated for N items at pointer P.
* *
* The memory block is filled with zeroes before being released. * The memory block is filled with zeroes before being released.
* The pointer argument is tagged as "volatile" to prevent the
* compiler optimizing out this critical step.
*/ */
void deallocate(volatile pointer p, size_type n) { void deallocate(pointer p, size_type n) {
std::memset(p, 0, n * sizeof(T)); // memset_s is used because memset may be optimized away by the compiler
memset_s(p, n * sizeof(T), 0, n * sizeof(T));
// free using "global operator delete" // free using "global operator delete"
::operator delete(p); ::operator delete(p);
} }

View File

@ -263,10 +263,10 @@ private:
CZString(ArrayIndex index); CZString(ArrayIndex index);
CZString(char const* str, unsigned length, DuplicationPolicy allocate); CZString(char const* str, unsigned length, DuplicationPolicy allocate);
CZString(CZString const& other); CZString(CZString const& other);
CZString(CZString&& other); CZString(CZString&& other) noexcept;
~CZString(); ~CZString();
CZString& operator=(const CZString& other); CZString& operator=(const CZString& other);
CZString& operator=(CZString&& other); CZString& operator=(CZString&& other) noexcept;
bool operator<(CZString const& other) const; bool operator<(CZString const& other) const;
bool operator==(CZString const& other) const; bool operator==(CZString const& other) const;
@ -344,13 +344,13 @@ public:
Value(bool value); Value(bool value);
Value(std::nullptr_t ptr) = delete; Value(std::nullptr_t ptr) = delete;
Value(const Value& other); Value(const Value& other);
Value(Value&& other); Value(Value&& other) noexcept;
~Value(); ~Value();
/// \note Overwrite existing comments. To preserve comments, use /// \note Overwrite existing comments. To preserve comments, use
/// #swapPayload(). /// #swapPayload().
Value& operator=(const Value& other); Value& operator=(const Value& other);
Value& operator=(Value&& other); Value& operator=(Value&& other) noexcept;
/// Swap everything. /// Swap everything.
void swap(Value& other); void swap(Value& other);
@ -635,9 +635,9 @@ private:
public: public:
Comments() = default; Comments() = default;
Comments(const Comments& that); Comments(const Comments& that);
Comments(Comments&& that); Comments(Comments&& that) noexcept;
Comments& operator=(const Comments& that); Comments& operator=(const Comments& that);
Comments& operator=(Comments&& that); Comments& operator=(Comments&& that) noexcept;
bool has(CommentPlacement slot) const; bool has(CommentPlacement slot) const;
String get(CommentPlacement slot) const; String get(CommentPlacement slot) const;
void set(CommentPlacement slot, String comment); void set(CommentPlacement slot, String comment);

View File

@ -9,10 +9,10 @@
// 3. /CMakeLists.txt // 3. /CMakeLists.txt
// IMPORTANT: also update the SOVERSION!! // IMPORTANT: also update the SOVERSION!!
#define JSONCPP_VERSION_STRING "1.9.3" #define JSONCPP_VERSION_STRING "1.9.4"
#define JSONCPP_VERSION_MAJOR 1 #define JSONCPP_VERSION_MAJOR 1
#define JSONCPP_VERSION_MINOR 9 #define JSONCPP_VERSION_MINOR 9
#define JSONCPP_VERSION_PATCH 3 #define JSONCPP_VERSION_PATCH 4
#define JSONCPP_VERSION_QUALIFIER #define JSONCPP_VERSION_QUALIFIER
#define JSONCPP_VERSION_HEXA \ #define JSONCPP_VERSION_HEXA \
((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \ ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \

View File

@ -9,7 +9,7 @@ project(
# 2. /include/json/version.h # 2. /include/json/version.h
# 3. /CMakeLists.txt # 3. /CMakeLists.txt
# IMPORTANT: also update the SOVERSION!! # IMPORTANT: also update the SOVERSION!!
version : '1.9.3', version : '1.9.4',
default_options : [ default_options : [
'buildtype=release', 'buildtype=release',
'cpp_std=c++11', 'cpp_std=c++11',

1
reformat.sh Executable file
View File

@ -0,0 +1 @@
find src -name '*.cpp' -or -name '*.h' | xargs clang-format -i

View File

@ -1921,7 +1921,7 @@ bool CharReaderBuilder::validate(Json::Value* invalid) const {
if (valid_keys.count(key)) if (valid_keys.count(key))
continue; continue;
if (invalid) if (invalid)
(*invalid)[std::move(key)] = *si; (*invalid)[key] = *si;
else else
return false; return false;
} }

View File

@ -259,7 +259,7 @@ Value::CZString::CZString(const CZString& other) {
storage_.length_ = other.storage_.length_; storage_.length_ = other.storage_.length_;
} }
Value::CZString::CZString(CZString&& other) Value::CZString::CZString(CZString&& other) noexcept
: cstr_(other.cstr_), index_(other.index_) { : cstr_(other.cstr_), index_(other.index_) {
other.cstr_ = nullptr; other.cstr_ = nullptr;
} }
@ -285,7 +285,7 @@ Value::CZString& Value::CZString::operator=(const CZString& other) {
return *this; return *this;
} }
Value::CZString& Value::CZString::operator=(CZString&& other) { Value::CZString& Value::CZString::operator=(CZString&& other) noexcept {
cstr_ = other.cstr_; cstr_ = other.cstr_;
index_ = other.index_; index_ = other.index_;
other.cstr_ = nullptr; other.cstr_ = nullptr;
@ -433,7 +433,7 @@ Value::Value(const Value& other) {
dupMeta(other); dupMeta(other);
} }
Value::Value(Value&& other) { Value::Value(Value&& other) noexcept {
initBasic(nullValue); initBasic(nullValue);
swap(other); swap(other);
} }
@ -448,7 +448,7 @@ Value& Value::operator=(const Value& other) {
return *this; return *this;
} }
Value& Value::operator=(Value&& other) { Value& Value::operator=(Value&& other) noexcept {
other.swap(*this); other.swap(*this);
return *this; return *this;
} }
@ -1373,14 +1373,15 @@ bool Value::isObject() const { return type() == objectValue; }
Value::Comments::Comments(const Comments& that) Value::Comments::Comments(const Comments& that)
: ptr_{cloneUnique(that.ptr_)} {} : ptr_{cloneUnique(that.ptr_)} {}
Value::Comments::Comments(Comments&& that) : ptr_{std::move(that.ptr_)} {} Value::Comments::Comments(Comments&& that) noexcept
: ptr_{std::move(that.ptr_)} {}
Value::Comments& Value::Comments::operator=(const Comments& that) { Value::Comments& Value::Comments::operator=(const Comments& that) {
ptr_ = cloneUnique(that.ptr_); ptr_ = cloneUnique(that.ptr_);
return *this; return *this;
} }
Value::Comments& Value::Comments::operator=(Comments&& that) { Value::Comments& Value::Comments::operator=(Comments&& that) noexcept {
ptr_ = std::move(that.ptr_); ptr_ = std::move(that.ptr_);
return *this; return *this;
} }

View File

@ -1215,7 +1215,7 @@ bool StreamWriterBuilder::validate(Json::Value* invalid) const {
if (valid_keys.count(key)) if (valid_keys.count(key))
continue; continue;
if (invalid) if (invalid)
(*invalid)[std::move(key)] = *si; (*invalid)[key] = *si;
else else
return false; return false;
} }

View File

@ -3916,6 +3916,15 @@ JSONTEST_FIXTURE_LOCAL(MemberTemplateIs, BehavesSameAsNamedIs) {
} }
} }
class VersionTest : public JsonTest::TestCase {};
JSONTEST_FIXTURE_LOCAL(VersionTest, VersionNumbersMatch) {
std::ostringstream vstr;
vstr << JSONCPP_VERSION_MAJOR << '.' << JSONCPP_VERSION_MINOR << '.'
<< JSONCPP_VERSION_PATCH;
JSONTEST_ASSERT_EQUAL(vstr.str(), std::string(JSONCPP_VERSION_STRING));
}
#if defined(__GNUC__) #if defined(__GNUC__)
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif