Compare commits

..

70 Commits

Author SHA1 Message Date
Christopher Dunn
18e4d04e8e merged from 1.6.5 2015-07-23 00:32:47 -05:00
Christopher Dunn
d84702c903 1.6.5 2015-07-23 00:26:13 -05:00
Christopher Dunn
949babd7b0 Exceptions declared in header
resolves #272
2015-07-23 00:26:13 -05:00
Christopher Dunn
6ed877c77c correction for #316 2015-07-23 00:26:13 -05:00
Christopher Dunn
1c69568f8d Merge pull request #316 from filipjs/master
Update json_tool.h

typo in a comment
2015-07-17 06:44:33 -05:00
filipjs
770fdda28b Update json_tool.h
Fix a typo in comment.
2015-07-14 14:34:07 +02:00
Christopher Dunn
d48bff5fcb gcc-4.6 in Travis
and clang-3.0, the default
2015-07-12 15:02:28 -05:00
Christopher Dunn
93d74678da Merge pull request #315 from cdunn2001/0.y.z
-Werror

and fixed a minor bug found by -Wshadow
2015-07-12 14:52:00 -05:00
Christopher Dunn
ed5d73fe1d 0.6.4 2015-07-12 14:47:59 -05:00
Christopher Dunn
b97e624ac1 -Werror 2015-07-12 14:47:58 -05:00
Christopher Dunn
542354902e fixed a bug found by -Wshadow 2015-07-12 14:47:37 -05:00
Christopher Dunn
17360f3d4b fix some warnings 2015-07-12 14:47:37 -05:00
Christopher Dunn
75747db30c -Wshadow
* https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
* http://programmers.stackexchange.com/questions/122608/clang-warning-flags-for-objective-c-development/124574#124574

In clang: `-Wconversion` implies `-Wshorten-64-to-32`, but we cannot use
`-Wconversion` yet.
2015-07-12 14:47:35 -05:00
Christopher Dunn
81cf237917 Merge pull request #314 from cdunn2001/master
-Werror

plus small bug-fix
2015-07-12 14:38:02 -05:00
Christopher Dunn
cac79543f8 1.6.4
minor bug-fix
2015-07-12 14:29:53 -05:00
Christopher Dunn
d8186f36a6 -Werror 2015-07-12 14:28:55 -05:00
Christopher Dunn
7f240623d3 fixed a bug found by -Wshadow 2015-07-12 14:28:55 -05:00
Christopher Dunn
784433ac72 fix some warnings 2015-07-12 14:28:37 -05:00
Christopher Dunn
7275e3ce3c drop -Wsign-conversion 2015-07-12 12:49:57 -05:00
Christopher Dunn
46aa9d75fa -Wconversion
* https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
* http://programmers.stackexchange.com/questions/122608/clang-warning-flags-for-objective-c-development/124574#124574

In clang: `-Wconversion` implies `-Wshorten-64-to-32`
2015-07-12 12:39:04 -05:00
Christopher Dunn
f94a0e8989 auto-generated file with minor update 2015-07-12 12:31:43 -05:00
Christopher Dunn
e22a2f36f7 Merge pull request #313 from cdunn2001/master
`-std=c++11` for gcc builds too

There was an issue with Travis, but we seem to be past that now.

We were using only -std=c++0x for gcc, as you can see in the diff.

resolves #134
2015-07-12 12:18:28 -05:00
Christopher Dunn
fac87108a4 -std=c++11 for gcc builds too 2015-07-12 12:08:34 -05:00
Christopher Dunn
14fc9f124e Merge pull request #312 from cdunn2001/master
gcc-4.9, clang (3.0)
2015-07-12 12:04:41 -05:00
Christopher Dunn
658fa37e63 gcc-4.9, clang (3.0) 2015-07-12 11:53:49 -05:00
Christopher Dunn
02839ef5b1 Merge pull request #310 from cdunn2001/0.y.z
gcc-4.6, clang-3.3
2015-07-12 09:55:20 -05:00
Christopher Dunn
138c48b7e8 gcc-4.6, clang-3.3 2015-07-12 09:50:14 -05:00
Christopher Dunn
72fb4a5b08 valgrind in Travis 2015-07-11 14:26:11 -05:00
Christopher Dunn
c6fa959318 dockerize the Travis build
Docker builds are *much* faster in Travis.

Also, we prepare to enable C++11.
2015-07-11 14:26:11 -05:00
Christopher Dunn
056e5f9b64 Merge pull request #309 from cdunn2001/master
dockerize the Travis build, and allow C++11
2015-07-11 14:19:02 -05:00
Christopher Dunn
d8e8c14ffc valgrind in Travis 2015-07-11 14:11:45 -05:00
Christopher Dunn
fb1301274f Merge pull request #308 from cdunn2001/0.y.z
0.10.3

No significant changes.
2015-07-11 14:07:55 -05:00
Christopher Dunn
f4e6fccd46 dockerize the Travis build
Docker builds are *much* faster in Travis.

Also, we prepare to enable C++11.
2015-07-11 14:06:18 -05:00
Christopher Dunn
7670e5151b 0.10.3 2015-07-11 13:53:05 -05:00
Mike Naberezny
2e185081b2 Fix undefined name "sys"
Same as #299 (bca0eff81a1c5ef160d9858b8e89b1c919b71c1f), but an earlier
commit needed to be rebased.
2015-07-11 13:52:27 -05:00
Stuart Eichert
cb8259f545 Fix #296: Explicitly cast size_t results to unsigned when needed
This is rebased from #297, where AppVeyor had been failing, and which
was not properly based on the master branch.
2015-07-11 13:52:27 -05:00
Stuart Eichert
bb5d0249ed Warn about implicit 64 to 32 bit conversions when using clang 2015-07-11 13:52:08 -05:00
Martyn Gigg
710260d070 Allow an optional suffix on the debug library name in CMake. 2015-07-11 13:51:40 -05:00
Christopher Dunn
2428889813 1.6.3 2015-07-11 13:41:13 -05:00
Christopher Dunn
89704039a0 minor doc fix, for #302 2015-07-11 12:11:00 -05:00
Christopher Dunn
dbda2aa36f Merge pull request #307 from cdunn2001/gaurav-fix-warnings
fix warnings (-Wno-long-long and unused tokenStart)

* closes #300
* closes #301
2015-07-11 12:02:22 -05:00
Gaurav
ef38374e99 Gcc warning unused "tokenStart"
(was #301)

In `0.y.z` branch, `tokenStart` is not used.
Comment it as done in other cases.
2015-07-11 11:57:21 -05:00
Gaurav
f1cafb6ded GCC warning removal for long long
(was #300)

I got below warning message on x86 linux machine :
```
"jsoncpp-0.10.2-p1/include/json/config.h💯 warning: ISO C++ 1998 does not support ‘long long’"
gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
```
In reference to

* https://github.com/open-source-parsers/jsoncpp/pull/292

**long long** is supported in c++-11; for old compilers i.e `0.y.z` branch this patch should be merged.
2015-07-11 11:55:13 -05:00
Christopher Dunn
a13303e456 Merge pull request #306 from cdunn2001/0.y.z
fix appveyor 32-bit windows build
2015-07-11 11:52:16 -05:00
Christopher Dunn
7bc97db496 fix appveyor 32-bit windows build
* http://help.appveyor.com/discussions/problems/2229-v140-not-found-on-vs2105rc
```
Done Building Project "C:\projects\jsoncpp\jsoncpp.sln" (default targets) -- FAILED.

Build FAILED.

"C:\projects\jsoncpp\jsoncpp.sln" (default target) (1) ->
"C:\projects\jsoncpp\ALL_BUILD.vcxproj.metaproj" (default target) (2) ->
"C:\projects\jsoncpp\ZERO_CHECK.vcxproj" (default target) (3) ->
(PlatformPrepareForBuild target) ->
  C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB8020: The build tools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 build tools, please install v140 build tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Upgrade Solution...". [C:\projects\jsoncpp\ZERO_CHECK.vcxproj]
```
2015-07-11 11:36:28 -05:00
Christopher Dunn
6ca8ffcb91 Merge pull request #305 from cdunn2001/fix-fixeol-undefined-name-sys
Fix undefined name "sys"

Same as #299 (bca0eff), but an earlier commit needed to be rebased.
2015-07-11 11:17:09 -05:00
Mike Naberezny
b5e70f950e Fix undefined name "sys"
Same as #299 (bca0eff81a1c5ef160d9858b8e89b1c919b71c1f), but an earlier
commit needed to be rebased.
2015-07-11 11:15:43 -05:00
Christopher Dunn
b26804d1c2 Merge pull request #304 from cdunn2001/297
Same as #297 (1c4f274ab3), but properly rebased
2015-07-11 11:08:47 -05:00
Stuart Eichert
702a539762 Fix #296: Explicitly cast size_t results to unsigned when needed
This is rebased from #297, where AppVeyor had been failing, and which
was not properly based on the master branch.
2015-07-11 11:00:18 -05:00
Stuart Eichert
81cb7e5c5b Warn about implicit 64 to 32 bit conversions when using clang 2015-07-11 10:59:56 -05:00
Christopher Dunn
d259f608fd Merge pull request #303 from cdunn2001/appveyor-14.0
fix appveyor 32-bit windows build

I've backed rebased under #297 because AppVeyor has been failing since there, and because that was not properly based on master anyway.
2015-07-11 10:58:59 -05:00
Christopher Dunn
4652f818fe fix appveyor 32-bit windows build
* http://help.appveyor.com/discussions/problems/2229-v140-not-found-on-vs2105rc
```
Done Building Project "C:\projects\jsoncpp\jsoncpp.sln" (default targets) -- FAILED.

Build FAILED.

"C:\projects\jsoncpp\jsoncpp.sln" (default target) (1) ->
"C:\projects\jsoncpp\ALL_BUILD.vcxproj.metaproj" (default target) (2) ->
"C:\projects\jsoncpp\ZERO_CHECK.vcxproj" (default target) (3) ->
(PlatformPrepareForBuild target) ->
  C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB8020: The build tools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 build tools, please install v140 build tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Upgrade Solution...". [C:\projects\jsoncpp\ZERO_CHECK.vcxproj]
```
2015-07-11 10:53:13 -05:00
Christopher Dunn
ce32274ba5 Merge pull request #295 from martyngigg/master
Allow an optional suffix on the debug library name in CMake
2015-07-01 03:18:33 -05:00
Martyn Gigg
717c791d4e Allow an optional suffix on the debug library name in CMake. 2015-06-29 19:20:08 +01:00
Christopher Dunn
17181acf74 Merge remote-tracking branch 'up/master' into 0.y.z
fix ,/. problem in #294
2015-06-19 00:11:52 -05:00
Christopher Dunn
6e52e272da Merge pull request #294 from cdunn2001/master
fix ,/. problem in reader
2015-06-19 00:10:32 -05:00
Christopher Dunn
6416350438 fix ,/. problem in reader
fixes #293
2015-06-18 22:45:36 -05:00
Christopher Dunn
07623b71f2 Merge branch 'master' into 0.y.z 2015-06-18 22:34:40 -05:00
Christopher Dunn
bcb83b921c fix doxybuild.py for Windows
issue #287 (tylerknott@)
2015-06-18 22:26:44 -05:00
Christopher Dunn
f1ff13767c Merge pull request #291 from cdunn2001/0.y.z
fix #290
2015-06-10 22:05:45 -05:00
Christopher Dunn
3f05b1a897 Merge pull request #276 from bmyerz/master
make the unix cmake example work
2015-05-21 00:47:35 -05:00
Christopher Dunn
de2c85f576 Merge pull request #282 from keithkml/patch-1
Clarify which parts of README for users vs devs
2015-05-20 20:33:31 -05:00
Christopher Dunn
b389d81bf9 Merge pull request #280 from mgorny/pkg-config-fix
Fix custom includedir & libdir substitution in pkg-config
2015-05-20 20:24:37 -05:00
Keith Lea
89c51f3457 Clarify which parts of README for users vs devs
When I arrived at the JsonCpp GitHub page, as an intermediate C++ developer, I could not figure out how to include JsonCpp into my project. The changes I propose to the README make this much clearer, and define a clear distinction between which instructions are for those developing and contributing to JsonCpp, and those who are just using it.
2015-05-20 09:43:47 -07:00
Michał Górny
e6f1cffdd3 Fix custom includedir & libdir substitution in pkg-config
Do not prepend ${prefix} to substituted includedir & libdir
in the pkg-config file -- if the paths are overriden by user, CMake puts
absolute paths there (even if user specifies a relative path). Instead,
use the absolute path provided by CMake and appropriately default
LIBRARY_INSTALL_DIR & INCLUDE_INSTALL_DIR to absolute paths with
${CMAKE_INSTALL_PREFIX} prepended.

Fixes: https://github.com/open-source-parsers/jsoncpp/issues/279
Signed-off-by: Michał Górny <mgorny@gentoo.org>
2015-05-19 17:32:31 +02:00
Christopher Dunn
64441486ac Merge pull request #275 from stefan-it/stefan/cmake-generator-fix
[Documentation][Markdown] Use correct help option for cmake.
2015-05-19 01:53:11 -05:00
Christopher Dunn
d5e54d2609 Merge pull request #277 from gogo40/master
fix compile error on android

But note that we do not have continuous integration testing for Android. This could break again.

`snprintf` drives me crazy. It should have been part of every C library 20 years ago.
2015-05-19 01:52:57 -05:00
Péricles Lopes Machado
97e093a361 fix compile error on android 2015-05-18 14:31:05 -03:00
Brandon Myers
d57ac97db8 make the unix make example work
...by setting the archive directory variable
2015-05-18 10:06:21 -07:00
Stefan Schweter
31e9962754 [Documentation][Markdown] Use correct help option for cmake. 2015-05-17 13:04:40 +02:00
17 changed files with 165 additions and 163 deletions

View File

@@ -2,13 +2,30 @@
# http://about.travis-ci.org/docs/user/build-configuration/
# This file can be validated on:
# http://lint.travis-ci.org/
# See also
# http://stackoverflow.com/questions/22111549/travis-ci-with-clang-3-4-and-c11/30925448#30925448
# to allow C++11, though we are not yet building with -std=c++11
#before_install: sudo apt-get install -y cmake
# cmake is pre-installed in Travis for both linux and osx
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq valgrind
install:
# /usr/bin/gcc is 4.6 always, but gcc-X.Y is available.
#- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.6" CC="gcc-4.6"; fi
# /usr/bin/clang is our version already, and clang-X.Y does not exist.
#- if [ "$CXX" = "clang++" ]; then export CXX="clang++-3.0" CC="clang-3.0"; fi
- echo ${PATH}
- ls /usr/local
- export PATH=/usr/bin:${PATH}
- echo ${CXX}
- ${CXX} --version
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.6
- g++-4.6
- clang
- valgrind
os:
- linux
language: cpp
@@ -21,5 +38,5 @@ env:
- SHARED_LIB=ON STATIC_LIB=ON CMAKE_PKG=ON BUILD_TYPE=release VERBOSE_MAKE=false
- SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug VERBOSE_MAKE=true VERBOSE
notifications:
email:
- aaronjjacobs@gmail.com
email: false
sudo: false

View File

@@ -21,15 +21,16 @@ IF(NOT WIN32)
ENDIF(NOT CMAKE_BUILD_TYPE)
ENDIF(NOT WIN32)
SET(DEBUG_LIBNAME_SUFFIX "" CACHE STRING "Optional suffix to append to the library name for a debug build")
SET(LIB_SUFFIX "" CACHE STRING "Optional arch-dependent suffix for the library installation directory")
SET(RUNTIME_INSTALL_DIR bin
CACHE PATH "Install dir for executables and dlls")
SET(ARCHIVE_INSTALL_DIR lib${LIB_SUFFIX}
SET(ARCHIVE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}
CACHE PATH "Install dir for static libraries")
SET(LIBRARY_INSTALL_DIR lib${LIB_SUFFIX}
SET(LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}
CACHE PATH "Install dir for shared libraries")
SET(INCLUDE_INSTALL_DIR include
SET(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include
CACHE PATH "Install dir for headers")
SET(PACKAGE_INSTALL_DIR lib${LIB_SUFFIX}/cmake
CACHE PATH "Install dir for cmake package config files")
@@ -62,7 +63,7 @@ ENDMACRO(jsoncpp_parse_version)
#SET( JSONCPP_VERSION_MAJOR X )
#SET( JSONCPP_VERSION_MINOR Y )
#SET( JSONCPP_VERSION_PATCH Z )
SET( JSONCPP_VERSION 0.10.2 )
SET( JSONCPP_VERSION 0.10.5 )
jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION )
#IF(NOT JSONCPP_VERSION_FOUND)
# MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z")
@@ -96,10 +97,11 @@ endif( MSVC )
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# using regular Clang or AppleClang
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wall -Wshadow -Wshorten-64-to-32")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# using GCC
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wshadow -Wextra -pedantic -Wno-long-long")
# not yet ready for -Wconversion
endif()
IF(JSONCPP_WITH_WARNING_AS_ERROR)

View File

@@ -19,12 +19,14 @@ format to store user input files.
* `0.y.z` can be used with older compilers.
* Major versions maintain binary-compatibility.
Using JsonCpp in your project
# Using JsonCpp in your project
-----------------------------
The recommended approach to integrating JsonCpp in your project is to build
the amalgamated source (a single `.cpp` file) with your own build system. This
ensures consistency of compilation flags and ABI compatibility. See the section
"Generating amalgamated source and header" for instructions.
The recommended approach to integrating JsonCpp in your project is to include
the [amalgamated source](#generating-amalgamated-source-and-header) (a single
`.cpp` file and two `.h` files) in your project, and compile and build as you
would any other source file. This ensures consistency of compilation flags and
ABI compatibility, issues which arise when building shared or static
libraries. See the next section for instructions.
The `include/` should be added to your compiler include path. Jsoncpp headers
should be included as follow:
@@ -34,6 +36,31 @@ should be included as follow:
If JsonCpp was built as a dynamic library on Windows, then your project needs to
define the macro `JSON_DLL`.
Generating amalgamated source and header
----------------------------------------
JsonCpp is provided with a script to generate a single header and a single
source file to ease inclusion into an existing project. The amalgamated source
can be generated at any time by running the following command from the
top-directory (this requires Python 2.6):
python amalgamate.py
It is possible to specify header name. See the `-h` option for detail.
By default, the following files are generated:
* `dist/jsoncpp.cpp`: source file that needs to be added to your project.
* `dist/json/json.h`: corresponding header file for use in your project. It is
equivalent to including `json/json.h` in non-amalgamated source. This header
only depends on standard headers.
* `dist/json/json-forwards.h`: header that provides forward declaration of all
JsonCpp types.
The amalgamated sources are generated by concatenating JsonCpp source in the
correct order and defining the macro `JSON_IS_AMALGAMATION` to prevent inclusion
of other headers.
# Contributing to JsonCpp
Building and testing with CMake
-------------------------------
[CMake][] is a C++ Makefiles/Solution generator. It is usually available on most
@@ -67,10 +94,10 @@ Alternatively, from the command-line on Unix in the source directory:
mkdir -p build/debug
cd build/debug
cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -G "Unix Makefiles" ../..
cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DARCHIVE_INSTALL_DIR=. -G "Unix Makefiles" ../..
make
Running `cmake -`" will display the list of available generators (passed using
Running `cmake -h` will display the list of available generators (passed using
the `-G` option).
By default CMake hides compilation commands. This can be modified by specifying
@@ -106,7 +133,7 @@ If you are building with Microsoft Visual Studio 2008, you need to set up the
environment by running `vcvars32.bat` (e.g. MSVC 2008 command prompt) before
running SCons.
# Running the tests manually
## Running the tests manually
You need to run tests manually only if you are troubleshooting an issue.
In the instructions below, replace `path/to/jsontest` with the path of the
@@ -142,29 +169,6 @@ Run the Python script `doxybuild.py` from the top directory:
See `doxybuild.py --help` for options.
Generating amalgamated source and header
----------------------------------------
JsonCpp is provided with a script to generate a single header and a single
source file to ease inclusion into an existing project. The amalgamated source
can be generated at any time by running the following command from the
top-directory (this requires Python 2.6):
python amalgamate.py
It is possible to specify header name. See the `-h` option for detail.
By default, the following files are generated:
* `dist/jsoncpp.cpp`: source file that needs to be added to your project.
* `dist/json/json.h`: corresponding header file for use in your project. It is
equivalent to including `json/json.h` in non-amalgamated source. This header
only depends on standard headers.
* `dist/json/json-forwards.h`: header that provides forward declaration of all
JsonCpp types.
The amalgamated sources are generated by concatenating JsonCpp source in the
correct order and defining the macro `JSON_IS_AMALGAMATION` to prevent inclusion
of other headers.
Adding a reader/writer test
---------------------------
To add a test, you need to create two files in test/data:

View File

@@ -19,6 +19,7 @@ before_build:
- echo "Running cmake..."
- cd c:\projects\jsoncpp
- cmake --version
- set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH%
- if %PLATFORM% == Win32 cmake .
- if %PLATFORM% == x64 cmake -G "Visual Studio 12 2013 Win64" .

View File

@@ -5,6 +5,7 @@
from __future__ import print_function
import os.path
import sys
def fix_source_eol(path, is_dry_run = True, verbose = True, eol = '\n'):
"""Makes sure that all sources have the specified eol sequence (default: unix)."""

View File

@@ -72,7 +72,7 @@ def run_cmd(cmd, silent=False):
if silent:
status, output = getstatusoutput(cmd)
else:
status, output = os.system(' '.join(cmd)), ''
status, output = subprocess.call(cmd), ''
if status:
msg = 'Error while %s ...\n\terror=%d, output="""%s"""' %(info, status, output)
raise Exception(msg)

View File

@@ -37,21 +37,36 @@ namespace Json {
*
* We use nothing but these internally. Of course, STL can throw others.
*/
class JSON_API Exception;
class JSON_API Exception : public std::exception {
public:
Exception(std::string const& msg);
virtual ~Exception() throw();
virtual char const* what() const throw();
protected:
std::string const msg_;
};
/** Exceptions which the user cannot easily avoid.
*
* E.g. out-of-memory (when we use malloc), stack-overflow, malicious input
*
* \remark derived from Json::Exception
*/
class JSON_API RuntimeError;
class JSON_API RuntimeError : public Exception {
public:
RuntimeError(std::string const& msg);
};
/** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
*
* These are precondition-violations (user bugs) and internal errors (our bugs).
*
* \remark derived from Json::Exception
*/
class JSON_API LogicError;
class JSON_API LogicError : public Exception {
public:
LogicError(std::string const& msg);
};
/// used internally
void throwRuntimeError(std::string const& msg);
@@ -258,7 +273,7 @@ Json::Value obj_value(Json::objectValue); // {}
#endif // if defined(JSON_HAS_INT64)
Value(double value);
Value(const char* value); ///< Copy til first 0. (NULL causes to seg-fault.)
Value(const char* beginValue, const char* endValue); ///< Copy all, incl zeroes.
Value(const char* begin, const char* end); ///< Copy all, incl zeroes.
/** \brief Constructs a value from a static string.
* Like other value string constructor but do not duplicate the string for
@@ -309,7 +324,7 @@ Json::Value obj_value(Json::objectValue); // {}
* \return false if !string. (Seg-fault if str or end are NULL.)
*/
bool getString(
char const** str, char const** end) const;
char const** begin, char const** end) const;
#ifdef JSON_USE_CPPTL
CppTL::ConstString asConstString() const;
#endif
@@ -438,8 +453,8 @@ Json::Value obj_value(Json::objectValue); // {}
Value get(const char* key, const Value& defaultValue) const;
/// Return the member named key if it exist, defaultValue otherwise.
/// \note deep copy
/// \param key may contain embedded nulls.
Value get(const char* key, const char* end, const Value& defaultValue) const;
/// \note key may contain embedded nulls.
Value get(const char* begin, const char* end, const Value& defaultValue) const;
/// Return the member named key if it exist, defaultValue otherwise.
/// \note deep copy
/// \param key may contain embedded nulls.
@@ -451,12 +466,12 @@ Json::Value obj_value(Json::objectValue); // {}
#endif
/// Most general and efficient version of isMember()const, get()const,
/// and operator[]const
/// \note As stated elsewhere, behavior is undefined if (end-key) >= 2^30
Value const* find(char const* key, char const* end) const;
/// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30
Value const* find(char const* begin, char const* end) const;
/// Most general and efficient version of object-mutators.
/// \note As stated elsewhere, behavior is undefined if (end-key) >= 2^30
/// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30
/// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue.
Value const* demand(char const* key, char const* end);
Value const* demand(char const* begin, char const* end);
/// \brief Remove and return the named member.
///
/// Do nothing if it did not exist.
@@ -469,7 +484,7 @@ Json::Value obj_value(Json::objectValue); // {}
/// \param key may contain embedded nulls.
/// \deprecated
Value removeMember(const std::string& key);
/// Same as removeMember(const char* key, const char* end, Value* removed),
/// Same as removeMember(const char* begin, const char* end, Value* removed),
/// but 'key' is null-terminated.
bool removeMember(const char* key, Value* removed);
/** \brief Remove the named map member.
@@ -480,7 +495,7 @@ Json::Value obj_value(Json::objectValue); // {}
*/
bool removeMember(std::string const& key, Value* removed);
/// Same as removeMember(std::string const& key, Value* removed)
bool removeMember(const char* key, const char* end, Value* removed);
bool removeMember(const char* begin, const char* end, Value* removed);
/** \brief Remove the indexed array element.
O(n) expensive operations.
@@ -496,7 +511,7 @@ Json::Value obj_value(Json::objectValue); // {}
/// \param key may contain embedded nulls.
bool isMember(const std::string& key) const;
/// Same as isMember(std::string const& key)const
bool isMember(const char* key, const char* end) const;
bool isMember(const char* begin, const char* end) const;
#ifdef JSON_USE_CPPTL
/// Return true if the object has a member named key.
bool isMember(const CppTL::ConstString& key) const;

View File

@@ -1,13 +1,12 @@
// DO NOT EDIT. This file is generated by CMake from "version"
// and "version.h.in" files.
// DO NOT EDIT. This file (and "version") is generated by CMake.
// Run CMake configure step to update it.
#ifndef JSON_VERSION_H_INCLUDED
# define JSON_VERSION_H_INCLUDED
# define JSONCPP_VERSION_STRING "0.10.2"
# define JSONCPP_VERSION_STRING "0.10.5"
# define JSONCPP_VERSION_MAJOR 0
# define JSONCPP_VERSION_MINOR 10
# define JSONCPP_VERSION_PATCH 2
# define JSONCPP_VERSION_PATCH 5
# define JSONCPP_VERSION_QUALIFIER
# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))

View File

@@ -1,7 +1,7 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/@LIBRARY_INSTALL_DIR@
includedir=${prefix}/@INCLUDE_INSTALL_DIR@
libdir=@LIBRARY_INSTALL_DIR@
includedir=@INCLUDE_INSTALL_DIR@
Name: jsoncpp
Description: A C++ library for interacting with JSON

View File

@@ -2,7 +2,7 @@ if( CMAKE_COMPILER_IS_GNUCXX )
#Get compiler version.
execute_process( COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
OUTPUT_VARIABLE GNUCXX_VERSION )
#-Werror=* was introduced -after- GCC 4.1.2
if( GNUCXX_VERSION VERSION_GREATER 4.1.2 )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=strict-aliasing")
@@ -43,7 +43,8 @@ IF(BUILD_SHARED_LIBS)
ADD_DEFINITIONS( -DJSON_DLL_BUILD )
ADD_LIBRARY(jsoncpp_lib SHARED ${PUBLIC_HEADERS} ${jsoncpp_sources})
SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_VERSION_MAJOR})
SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES OUTPUT_NAME jsoncpp )
SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES OUTPUT_NAME jsoncpp
DEBUG_OUTPUT_NAME jsoncpp${DEBUG_LIBNAME_SUFFIX} )
INSTALL( TARGETS jsoncpp_lib ${INSTALL_EXPORT}
RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR}
@@ -61,7 +62,8 @@ ENDIF()
IF(BUILD_STATIC_LIBS)
ADD_LIBRARY(jsoncpp_lib_static STATIC ${PUBLIC_HEADERS} ${jsoncpp_sources})
SET_TARGET_PROPERTIES( jsoncpp_lib_static PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_VERSION_MAJOR})
SET_TARGET_PROPERTIES( jsoncpp_lib_static PROPERTIES OUTPUT_NAME jsoncpp )
SET_TARGET_PROPERTIES( jsoncpp_lib_static PROPERTIES OUTPUT_NAME jsoncpp
DEBUG_OUTPUT_NAME jsoncpp${DEBUG_LIBNAME_SUFFIX} )
INSTALL( TARGETS jsoncpp_lib_static ${INSTALL_EXPORT}
RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR}

View File

@@ -557,33 +557,9 @@ bool Reader::decodeDouble(Token& token) {
bool Reader::decodeDouble(Token& token, Value& decoded) {
double value = 0;
const int bufferSize = 32;
int count;
int length = int(token.end_ - token.start_);
// Sanity check to avoid buffer overflow exploits.
if (length < 0) {
return addError("Unable to parse token length", token);
}
// Avoid using a string constant for the format control string given to
// sscanf, as this can cause hard to debug crashes on OS X. See here for more
// info:
//
// http://developer.apple.com/library/mac/#DOCUMENTATION/DeveloperTools/gcc-4.0.1/gcc/Incompatibilities.html
char format[] = "%lf";
if (length <= bufferSize) {
Char buffer[bufferSize + 1];
memcpy(buffer, token.start_, length);
buffer[length] = 0;
count = sscanf(buffer, format, &value);
} else {
std::string buffer(token.start_, token.end_);
count = sscanf(buffer.c_str(), format, &value);
}
if (count != 1)
std::string buffer(token.start_, token.end_);
std::istringstream is(buffer);
if (!(is >> value))
return addError("'" + std::string(token.start_, token.end_) +
"' is not a number.",
token);
@@ -1289,7 +1265,7 @@ bool OurReader::readStringSingleQuote() {
return c == '\'';
}
bool OurReader::readObject(Token& tokenStart) {
bool OurReader::readObject(Token& /*tokenStart*/) {
Token tokenName;
std::string name;
Value init(objectValue);
@@ -1350,7 +1326,7 @@ bool OurReader::readObject(Token& tokenStart) {
"Missing '}' or object member name", tokenName, tokenObjectEnd);
}
bool OurReader::readArray(Token& tokenStart) {
bool OurReader::readArray(Token& /*tokenStart*/) {
Value init(arrayValue);
currentValue().swapPayload(init);
skipSpaces();

View File

@@ -30,8 +30,8 @@ static inline std::string codePointToUTF8(unsigned int cp) {
} else if (cp <= 0xFFFF) {
result.resize(3);
result[2] = static_cast<char>(0x80 | (0x3f & cp));
result[1] = 0x80 | static_cast<char>((0x3f & (cp >> 6)));
result[0] = 0xE0 | static_cast<char>((0xf & (cp >> 12)));
result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
result[0] = static_cast<char>(0xE0 | (0xf & (cp >> 12)));
} else if (cp <= 0x10FFFF) {
result.resize(4);
result[3] = static_cast<char>(0x80 | (0x3f & cp));
@@ -43,7 +43,7 @@ static inline std::string codePointToUTF8(unsigned int cp) {
return result;
}
/// Returns true if ch is a control character (in range [0,32[).
/// Returns true if ch is a control character (in range [1,31]).
static inline bool isControlCharacter(char ch) { return ch > 0 && ch <= 0x1F; }
enum {
@@ -63,7 +63,7 @@ typedef char UIntToStringBuffer[uintToStringBufferSize];
static inline void uintToString(LargestUInt value, char*& current) {
*--current = 0;
do {
*--current = char(value % 10) + '0';
*--current = static_cast<signed char>(value % 10U + static_cast<unsigned>('0'));
value /= 10;
} while (value != 0);
}

View File

@@ -109,7 +109,7 @@ static inline char* duplicateAndPrefixStringValue(
JSON_ASSERT_MESSAGE(length <= (unsigned)Value::maxInt - sizeof(unsigned) - 1U,
"in Json::Value::duplicateAndPrefixStringValue(): "
"length too big for prefixing");
unsigned actualLength = length + sizeof(unsigned) + 1U;
unsigned actualLength = length + static_cast<unsigned>(sizeof(unsigned)) + 1U;
char* newString = static_cast<char*>(malloc(actualLength));
if (newString == 0) {
throwRuntimeError(
@@ -126,7 +126,7 @@ inline static void decodePrefixedString(
unsigned* length, char const** value)
{
if (!isPrefixed) {
*length = strlen(prefixed);
*length = static_cast<unsigned>(strlen(prefixed));
*value = prefixed;
} else {
*length = *reinterpret_cast<unsigned const*>(prefixed);
@@ -153,23 +153,6 @@ static inline void releaseStringValue(char* value) { free(value); }
namespace Json {
class JSON_API Exception : public std::exception {
public:
Exception(std::string const& msg);
virtual ~Exception() throw();
virtual char const* what() const throw();
protected:
std::string const msg_;
};
class JSON_API RuntimeError : public Exception {
public:
RuntimeError(std::string const& msg);
};
class JSON_API LogicError : public Exception {
public:
LogicError(std::string const& msg);
};
Exception::Exception(std::string const& msg)
: msg_(msg)
{}
@@ -233,14 +216,14 @@ void Value::CommentInfo::setComment(const char* text, size_t len) {
// Notes: policy_ indicates if the string was allocated when
// a string is stored.
Value::CZString::CZString(ArrayIndex index) : cstr_(0), index_(index) {}
Value::CZString::CZString(ArrayIndex aindex) : cstr_(0), index_(aindex) {}
Value::CZString::CZString(char const* str, unsigned length, DuplicationPolicy allocate)
Value::CZString::CZString(char const* str, unsigned ulength, DuplicationPolicy allocate)
: cstr_(str)
{
// allocate != duplicate
storage_.policy_ = allocate;
storage_.length_ = length;
storage_.policy_ = allocate & 0x3;
storage_.length_ = ulength & 0x3FFFFFFF;
}
Value::CZString::CZString(const CZString& other)
@@ -249,9 +232,9 @@ Value::CZString::CZString(const CZString& other)
: other.cstr_)
{
storage_.policy_ = (other.cstr_
? (other.storage_.policy_ == noDuplication
? (static_cast<DuplicationPolicy>(other.storage_.policy_) == noDuplication
? noDuplication : duplicate)
: other.storage_.policy_);
: static_cast<DuplicationPolicy>(other.storage_.policy_));
storage_.length_ = other.storage_.length_;
}
@@ -313,9 +296,9 @@ bool Value::CZString::isStaticString() const { return storage_.policy_ == noDupl
* memset( this, 0, sizeof(Value) )
* This optimization is used in ValueInternalMap fast allocator.
*/
Value::Value(ValueType type) {
initBasic(type);
switch (type) {
Value::Value(ValueType vtype) {
initBasic(vtype);
switch (vtype) {
case nullValue:
break;
case intValue:
@@ -480,7 +463,7 @@ void Value::swapPayload(Value& other) {
std::swap(value_, other.value_);
int temp2 = allocated_;
allocated_ = other.allocated_;
other.allocated_ = temp2;
other.allocated_ = temp2 & 0x1;
}
void Value::swap(Value& other) {
@@ -606,12 +589,12 @@ const char* Value::asCString() const {
return this_str;
}
bool Value::getString(char const** str, char const** end) const {
bool Value::getString(char const** str, char const** cend) const {
if (type_ != stringValue) return false;
if (value_.string_ == 0) return false;
unsigned length;
decodePrefixedString(this->allocated_, this->value_.string_, &length, str);
*end = *str + length;
*cend = *str + length;
return true;
}
@@ -810,7 +793,8 @@ bool Value::asBool() const {
case uintValue:
return value_.uint_ ? true : false;
case realValue:
return value_.real_ ? true : false;
// This is kind of strange. Not recommended.
return (value_.real_ != 0.0) ? true : false;
default:
break;
}
@@ -958,8 +942,8 @@ const Value& Value::operator[](int index) const {
return (*this)[ArrayIndex(index)];
}
void Value::initBasic(ValueType type, bool allocated) {
type_ = type;
void Value::initBasic(ValueType vtype, bool allocated) {
type_ = vtype;
allocated_ = allocated;
comments_ = 0;
}
@@ -986,7 +970,7 @@ Value& Value::resolveReference(const char* key) {
}
// @param key is not null-terminated.
Value& Value::resolveReference(char const* key, char const* end)
Value& Value::resolveReference(char const* key, char const* cend)
{
JSON_ASSERT_MESSAGE(
type_ == nullValue || type_ == objectValue,
@@ -994,7 +978,7 @@ Value& Value::resolveReference(char const* key, char const* end)
if (type_ == nullValue)
*this = Value(objectValue);
CZString actualKey(
key, static_cast<unsigned>(end-key), CZString::duplicateOnCopy);
key, static_cast<unsigned>(cend-key), CZString::duplicateOnCopy);
ObjectValues::iterator it = value_.map_->lower_bound(actualKey);
if (it != value_.map_->end() && (*it).first == actualKey)
return (*it).second;
@@ -1012,13 +996,13 @@ Value Value::get(ArrayIndex index, const Value& defaultValue) const {
bool Value::isValidIndex(ArrayIndex index) const { return index < size(); }
Value const* Value::find(char const* key, char const* end) const
Value const* Value::find(char const* key, char const* cend) const
{
JSON_ASSERT_MESSAGE(
type_ == nullValue || type_ == objectValue,
"in Json::Value::find(key, end, found): requires objectValue or nullValue");
if (type_ == nullValue) return NULL;
CZString actualKey(key, static_cast<unsigned>(end-key), CZString::noDuplication);
CZString actualKey(key, static_cast<unsigned>(cend-key), CZString::noDuplication);
ObjectValues::const_iterator it = value_.map_->find(actualKey);
if (it == value_.map_->end()) return NULL;
return &(*it).second;
@@ -1062,9 +1046,9 @@ Value const& Value::operator[](CppTL::ConstString const& key) const
Value& Value::append(const Value& value) { return (*this)[size()] = value; }
Value Value::get(char const* key, char const* end, Value const& defaultValue) const
Value Value::get(char const* key, char const* cend, Value const& defaultValue) const
{
Value const* found = find(key, end);
Value const* found = find(key, cend);
return !found ? defaultValue : *found;
}
Value Value::get(char const* key, Value const& defaultValue) const
@@ -1077,12 +1061,12 @@ Value Value::get(std::string const& key, Value const& defaultValue) const
}
bool Value::removeMember(const char* key, const char* end, Value* removed)
bool Value::removeMember(const char* key, const char* cend, Value* removed)
{
if (type_ != objectValue) {
return false;
}
CZString actualKey(key, static_cast<unsigned>(end-key), CZString::noDuplication);
CZString actualKey(key, static_cast<unsigned>(cend-key), CZString::noDuplication);
ObjectValues::iterator it = value_.map_->find(actualKey);
if (it == value_.map_->end())
return false;
@@ -1127,8 +1111,8 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) {
ArrayIndex oldSize = size();
// shift left all items left, into the place of the "removed"
for (ArrayIndex i = index; i < (oldSize - 1); ++i){
CZString key(i);
(*value_.map_)[key] = (*this)[i + 1];
CZString keey(i);
(*value_.map_)[keey] = (*this)[i + 1];
}
// erase the last one ("leftover")
CZString keyLast(oldSize - 1);
@@ -1144,9 +1128,9 @@ Value Value::get(const CppTL::ConstString& key,
}
#endif
bool Value::isMember(char const* key, char const* end) const
bool Value::isMember(char const* key, char const* cend) const
{
Value const* value = find(key, end);
Value const* value = find(key, cend);
return NULL != value;
}
bool Value::isMember(char const* key) const

View File

@@ -93,26 +93,26 @@ UInt ValueIteratorBase::index() const {
}
std::string ValueIteratorBase::name() const {
char const* key;
char const* keey;
char const* end;
key = memberName(&end);
if (!key) return std::string();
return std::string(key, end);
keey = memberName(&end);
if (!keey) return std::string();
return std::string(keey, end);
}
char const* ValueIteratorBase::memberName() const {
const char* name = (*current_).first.data();
return name ? name : "";
const char* cname = (*current_).first.data();
return cname ? cname : "";
}
char const* ValueIteratorBase::memberName(char const** end) const {
const char* name = (*current_).first.data();
if (!name) {
const char* cname = (*current_).first.data();
if (!cname) {
*end = NULL;
return NULL;
}
*end = name + (*current_).first.length();
return name;
*end = cname + (*current_).first.length();
return cname;
}
// //////////////////////////////////////////////////////////////////

View File

@@ -29,6 +29,8 @@
#if defined(_MSC_VER) && _MSC_VER < 1500 // VC++ 8.0 and below
#define snprintf _snprintf
#elif defined(__ANDROID__)
#define snprintf snprintf
#elif __cplusplus >= 201103L
#define snprintf std::snprintf
#endif
@@ -341,7 +343,7 @@ void FastWriter::writeValue(const Value& value) {
const std::string& name = *it;
if (it != members.begin())
document_ += ',';
document_ += valueToQuotedStringN(name.data(), name.length());
document_ += valueToQuotedStringN(name.data(), static_cast<unsigned>(name.length()));
document_ += yamlCompatiblityEnabled_ ? ": " : ":";
writeValue(value[name]);
}
@@ -901,7 +903,7 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) {
std::string const& name = *it;
Value const& childValue = value[name];
writeCommentBeforeValue(childValue);
writeWithIndent(valueToQuotedStringN(name.data(), name.length()));
writeWithIndent(valueToQuotedStringN(name.data(), static_cast<unsigned>(name.length())));
*sout_ << colonSymbol_;
writeValue(childValue);
if (++it == members.end()) {

View File

@@ -1,5 +1,4 @@
// DO NOT EDIT. This file is generated by CMake from "version"
// and "version.h.in" files.
// DO NOT EDIT. This file (and "version") is generated by CMake.
// Run CMake configure step to update it.
#ifndef JSON_VERSION_H_INCLUDED
# define JSON_VERSION_H_INCLUDED

View File

@@ -1 +1 @@
0.10.2
0.10.5