From 90de18de8a77b7941b81f40c710f3536de042043 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 23 Jun 2017 21:21:17 +0200 Subject: [PATCH] Bug 1375957 - Bump the version of jsoncpp r=kip MozReview-Commit-ID: IwdWn9R4GRz --HG-- extra : rebase_source : fb3d0ee7bf5cf7aee5b1c871ea35192a55232513 --- toolkit/components/jsoncpp/AUTHORS | 110 +++++++++++++ toolkit/components/jsoncpp/GIT-INFO | 3 +- toolkit/components/jsoncpp/LICENSE | 6 +- toolkit/components/jsoncpp/README.md | 148 ++++++++++++------ .../jsoncpp/include/json/allocator.h | 4 + .../components/jsoncpp/include/json/config.h | 8 +- .../jsoncpp/include/json/features.h | 4 + .../components/jsoncpp/include/json/reader.h | 4 + .../components/jsoncpp/include/json/value.h | 7 +- .../components/jsoncpp/include/json/version.h | 6 +- .../components/jsoncpp/include/json/writer.h | 4 + .../jsoncpp/src/lib_json/json_reader.cpp | 41 +++-- .../jsoncpp/src/lib_json/json_tool.h | 10 +- .../jsoncpp/src/lib_json/json_value.cpp | 50 ++++-- .../jsoncpp/src/lib_json/json_writer.cpp | 26 +-- 15 files changed, 326 insertions(+), 105 deletions(-) diff --git a/toolkit/components/jsoncpp/AUTHORS b/toolkit/components/jsoncpp/AUTHORS index c0fbbeec1118..5747e61c1b28 100644 --- a/toolkit/components/jsoncpp/AUTHORS +++ b/toolkit/components/jsoncpp/AUTHORS @@ -1 +1,111 @@ Baptiste Lepilleur + +Aaron Jacobs +Aaron Jacobs +Adam Boseley +Adam Boseley +Aleksandr Derbenev <13alexac@gmail.com> +Alexander Gazarov +Alexander V. Brezgin +Alexandr Brezgin +Alexey Kruchinin +Anton Indrawan +Baptiste Jonglez +Baptiste Lepilleur +Baruch Siach +Ben Boeckel +Benjamin Knecht +Bernd Kuhls +Billy Donahue +Braden McDorman +Brandon Myers +Brendan Drew +chason +Chris Gilling +Christopher Dawes +Christopher Dunn +Chuck Atkins +Cody P Schafer +Connor Manning +Cory Quammen +Cristóvão B da Cruz e Silva +Daniel Krügler +Dani-Hub +Dan Liu +datadiode +datadiode +David Seifert +David West +dawesc +Dmitry Marakasov +dominicpezzuto +Don Milham +drgler +ds283 +Egor Tensin +eightnoteight +Evince +filipjs +findblar +Florian Meier +Gaëtan Lehmann +Gaurav +Gergely Nagy +Gida Pataki +I3ck +Iñaki Baz Castillo +Jacco +Jean-Christophe Fillion-Robin +Jonas Platte +Jörg Krause +Keith Lea +Kevin Grant +Kirill V. Lyadvinsky +Kirill V. Lyadvinsky +Kobi Gurkan +Magnus Bjerke Vik +Malay Shah +Mara Kim +Marek Kotewicz +Mark Lakata +Mark Zeren +Martin Buck +Martyn Gigg +Mattes D +Matthias Loy +Merlyn Morgan-Graham +Michael Shields +Michał Górny +Mike Naberezny +mloy +Motti +nnkur +Omkar Wagh +paulo +pavel.pimenov +Paweł Bylica +Péricles Lopes Machado +Peter Spiess-Knafl +pffang +Rémi Verschelde +renu555 +Robert Dailey +Sam Clegg +selaselah +Sergiy80 +sergzub +Stefan Schweter +Steffen Kieß +Steven Hahn +Stuart Eichert +SuperManitu +Techwolf +Tengiz Sharafiev +Tomasz Maciejewski +Vicente Olivert Riera +xiaoyur347 +ycqiu <429148848@qq.com> +yiqiju +Yu Xiaolei + +Google Inc. diff --git a/toolkit/components/jsoncpp/GIT-INFO b/toolkit/components/jsoncpp/GIT-INFO index 7d4836e9254d..4db695a813e0 100644 --- a/toolkit/components/jsoncpp/GIT-INFO +++ b/toolkit/components/jsoncpp/GIT-INFO @@ -1 +1,2 @@ -a304d61a7b3ee2700b52abc0b28412aabee782e5 +56efb6ba83f7c8d63d81e25b42b0367c48aa5f3c + diff --git a/toolkit/components/jsoncpp/LICENSE b/toolkit/components/jsoncpp/LICENSE index ca2bfe1a03ee..55a3b2db99eb 100644 --- a/toolkit/components/jsoncpp/LICENSE +++ b/toolkit/components/jsoncpp/LICENSE @@ -2,12 +2,12 @@ The JsonCpp library's source code, including accompanying documentation, tests and demonstration applications, are licensed under the following conditions... -The author (Baptiste Lepilleur) explicitly disclaims copyright in all +The JsonCpp Authors explicitly disclaim copyright in all jurisdictions which recognize such a disclaimer. In such jurisdictions, this software is released into the Public Domain. In jurisdictions which do not recognize Public Domain property (e.g. Germany as of -2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is +2010), this software is Copyright (c) 2007-2010 by The JsonCpp Authors, and is released under the terms of the MIT License (see below). In jurisdictions which recognize Public Domain property, the user of this @@ -23,7 +23,7 @@ described in clear, concise terms at: The full text of the MIT License follows: ======================================================================== -Copyright (c) 2007-2010 Baptiste Lepilleur +Copyright (c) 2007-2010 The JsonCpp Authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/toolkit/components/jsoncpp/README.md b/toolkit/components/jsoncpp/README.md index 93c8d1f593ad..fbc8ef692c32 100644 --- a/toolkit/components/jsoncpp/README.md +++ b/toolkit/components/jsoncpp/README.md @@ -1,5 +1,6 @@ -Introduction ------------- +# JsonCpp + +[![badge](https://img.shields.io/badge/conan.io-jsoncpp%2F1.8.0-green.svg?logo=data:image/png;base64%2CiVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAMAAAAolt3jAAAA1VBMVEUAAABhlctjlstkl8tlmMtlmMxlmcxmmcxnmsxpnMxpnM1qnc1sn85voM91oM11oc1xotB2oc56pNF6pNJ2ptJ8ptJ8ptN9ptN8p9N5qNJ9p9N9p9R8qtOBqdSAqtOAqtR%2BrNSCrNJ/rdWDrNWCsNWCsNaJs9eLs9iRvNuVvdyVv9yXwd2Zwt6axN6dxt%2Bfx%2BChyeGiyuGjyuCjyuGly%2BGlzOKmzOGozuKoz%2BKqz%2BOq0OOv1OWw1OWw1eWx1eWy1uay1%2Baz1%2Baz1%2Bez2Oe02Oe12ee22ujUGwH3AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfgBQkREyOxFIh/AAAAiklEQVQI12NgAAMbOwY4sLZ2NtQ1coVKWNvoc/Eq8XDr2wB5Ig62ekza9vaOqpK2TpoMzOxaFtwqZua2Bm4makIM7OzMAjoaCqYuxooSUqJALjs7o4yVpbowvzSUy87KqSwmxQfnsrPISyFzWeWAXCkpMaBVIC4bmCsOdgiUKwh3JojLgAQ4ZCE0AMm2D29tZwe6AAAAAElFTkSuQmCC)](http://www.conan.io/source/jsoncpp/1.8.0/theirix/ci) [JSON][json-org] is a lightweight data-interchange format. It can represent numbers, strings, ordered sequences of values, and collections of name/value @@ -7,37 +8,45 @@ pairs. [json-org]: http://json.org/ -[JsonCpp][] is a C++ library that allows manipulating JSON values, including +JsonCpp is a C++ library that allows manipulating JSON values, including serialization and deserialization to and from strings. It can also preserve existing comment in unserialization/serialization steps, making it a convenient format to store user input files. -[JsonCpp]: http://open-source-parsers.github.io/jsoncpp-docs/doxygen/index.html + +## Documentation + +[JsonCpp documentation][JsonCpp-documentation] is generated using [Doxygen][]. + +[JsonCpp-documentation]: http://open-source-parsers.github.io/jsoncpp-docs/doxygen/index.html +[Doxygen]: http://www.doxygen.org + ## A note on backward-compatibility + * `1.y.z` is built with C++11. * `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 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 +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 +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 + +The `include/` should be added to your compiler include path. JsonCpp headers should be included as follow: #include -If JsonCpp was built as a dynamic library on Windows, then your project needs to -define the macro `JSON_DLL`. +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 -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 @@ -48,6 +57,7 @@ top-directory (this requires Python 2.6): 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 @@ -56,15 +66,51 @@ By default, the following files are generated: 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. +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 -Linux system as package. On Ubuntu: +## Contributing to JsonCpp + +### Building and testing with Conan + +[Conan](https://www.conan.io/#/) is an open source package manager intended for C/C++ projects. +It is cross platform and build system agnostic. + +Conan requires Python for running, and can be installed using pip: + + pip install conan + + Detailed instructions can be found on [conan docs](http://docs.conan.io/en/latest/). + +For build jsoncpp with conan, you need to create a [conanfile.txt](http://docs.conan.io/en/latest/reference/conanfile_txt.html) or a [conanfile.py](http://docs.conan.io/en/latest/reference/conanfile.html). The first is simpler, but the second is more flexible. + +This is a sample conanfile.txt: + +``` +[requires] +jsoncpp/1.8.0@theirix/ci + +[generators] +cmake +``` + +**Note**: cmake is not required, you can use other [integrations](http://docs.conan.io/en/latest/integrations.html). Or you can set the appropriate environment variables, using [virtualenv generators](http://docs.conan.io/en/latest/mastering/virtualenv.html). + +Then run the following command from the conanfile directory: + + conan install --build missing + +This will try to download the appropriate package for your settings (OS, compiler, architecture) from the [recipe packages](https://www.conan.io/source/jsoncpp/1.8.0/theirix/ci). If it is not found, the package will be built. + +**Note**: you do not need to install cmake to build jsoncpp using conan, because the recipe will download it automatically. + +If you need, you can customize the jsoncpp recipe. Just clone/fork [it from github](https://github.com/theirix/conan-jsoncpp/). + +See [integrations instructions](http://docs.conan.io/en/latest/integrations.html) for how to use your build system with conan. + +### Building and testing with CMake + +[CMake][] is a C++ Makefiles/Solution generator. It is usually available on most Linux system as package. On Ubuntu: sudo apt-get install cmake @@ -75,10 +121,10 @@ missing, the build will skip running those tests. When running CMake, a few parameters are required: -* a build directory where the makefiles/solution are generated. It is also used +* A build directory where the makefiles/solution are generated. It is also used to store objects, libraries and executables files. -* the generator to use: makefiles or Visual Studio solution? What version or - Visual Studio, 32 or 64 bits solution? +* The generator to use: makefiles or Visual Studio solution? What version or + Visual Studio, 32 or 64 bits solution? Steps for generating solution/makefiles using `cmake-gui`: @@ -97,16 +143,20 @@ Alternatively, from the command-line on Unix in the source directory: cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DARCHIVE_INSTALL_DIR=. -G "Unix Makefiles" ../.. make +For a good pkg-config file, add: + + -DCMAKE_INSTALL_INCLUDEDIR=include/jsoncpp + 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 `-DCMAKE_VERBOSE_MAKEFILE=true` when generating makefiles. -Building and testing with SCons -------------------------------- -**Note:** The SCons-based build system is deprecated. Please use CMake; see the -section above. +### Building and testing with SCons + +**Note:** The SCons-based build system is deprecated. Please use CMake (see the +section above). JsonCpp can use [Scons][] as a build system. Note that SCons requires Python to be installed. @@ -133,7 +183,8 @@ 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,35 +193,36 @@ In the instructions below, replace `path/to/jsontest` with the path of the cd test # This will run the Reader/Writer tests python runjsontests.py path/to/jsontest - + # This will run the Reader/Writer tests, using JSONChecker test suite # (http://www.json.org/JSON_checker/). # Notes: not all tests pass: JsonCpp is too lenient (for example, # it allows an integer to start with '0'). The goal is to improve # strict mode parsing to get all tests to pass. python runjsontests.py --with-json-checker path/to/jsontest - + # This will run the unit tests (mostly Value) python rununittests.py path/to/test_lib_json - + # You can run the tests using valgrind: python rununittests.py --valgrind path/to/test_lib_json -## Running the tests using scons +### Running the tests using SCons + Note that tests can be run using SCons using the `check` target: scons platform=$PLATFORM check -Building the documentation --------------------------- +### Building the documentation + Run the Python script `doxybuild.py` from the top directory: python doxybuild.py --doxygen=$(which doxygen) --open --with-dot See `doxybuild.py --help` for options. -Adding a reader/writer test ---------------------------- +### Adding a reader/writer test + To add a test, you need to create two files in test/data: * a `TESTNAME.json` file, that contains the input document in JSON format. @@ -179,21 +231,19 @@ To add a test, you need to create two files in test/data: The `TESTNAME.expected` file format is as follows: -* each line represents a JSON element of the element tree represented by the +* Each line represents a JSON element of the element tree represented by the input document. -* each line has two parts: the path to access the element separated from the +* Each line has two parts: the path to access the element separated from the element value by `=`. Array and object values are always empty (i.e. represented by either `[]` or `{}`). -* element path: `.` represents the root element, and is used to separate object +* Element path `.` represents the root element, and is used to separate object members. `[N]` is used to specify the value of an array element at index `N`. -See the examples `test_complex_01.json` and `test_complex_01.expected` to better -understand element paths. +See the examples `test_complex_01.json` and `test_complex_01.expected` to better understand element paths. -Understanding reader/writer test output ---------------------------------------- -When a test is run, output files are generated beside the input test files. -Below is a short description of the content of each file: +### Understanding reader/writer test output + +When a test is run, output files are generated beside the input test files. Below is a short description of the content of each file: * `test_complex_01.json`: input JSON document. * `test_complex_01.expected`: flattened JSON element tree used to check if @@ -208,7 +258,7 @@ Below is a short description of the content of each file: * `test_complex_01.process-output`: `jsontest` output, typically useful for understanding parsing errors. -License -------- +## License + See the `LICENSE` file for details. In summary, JsonCpp is licensed under the MIT license, or public domain if desired and recognized in your jurisdiction. diff --git a/toolkit/components/jsoncpp/include/json/allocator.h b/toolkit/components/jsoncpp/include/json/allocator.h index 9d8b9fc9cfe8..2492758cd71d 100644 --- a/toolkit/components/jsoncpp/include/json/allocator.h +++ b/toolkit/components/jsoncpp/include/json/allocator.h @@ -9,6 +9,8 @@ #include #include +#pragma pack(push, 8) + namespace Json { template class SecureAllocator { @@ -91,4 +93,6 @@ bool operator!=(const SecureAllocator&, const SecureAllocator&) { } //namespace Json +#pragma pack(pop) + #endif // CPPTL_JSON_ALLOCATOR_H_INCLUDED diff --git a/toolkit/components/jsoncpp/include/json/config.h b/toolkit/components/jsoncpp/include/json/config.h index 7f77d0c56740..6e3f3ac647e7 100644 --- a/toolkit/components/jsoncpp/include/json/config.h +++ b/toolkit/components/jsoncpp/include/json/config.h @@ -83,10 +83,16 @@ // managable and fixes a set of common hard-to-find bugs. #if __cplusplus >= 201103L # define JSONCPP_OVERRIDE override -#elif defined(_MSC_VER) && _MSC_VER > 1600 +# define JSONCPP_NOEXCEPT noexcept +#elif defined(_MSC_VER) && _MSC_VER > 1600 && _MSC_VER < 1900 # define JSONCPP_OVERRIDE override +# define JSONCPP_NOEXCEPT throw() +#elif defined(_MSC_VER) && _MSC_VER >= 1900 +# define JSONCPP_OVERRIDE override +# define JSONCPP_NOEXCEPT noexcept #else # define JSONCPP_OVERRIDE +# define JSONCPP_NOEXCEPT throw() #endif #ifndef JSON_HAS_RVALUE_REFERENCES diff --git a/toolkit/components/jsoncpp/include/json/features.h b/toolkit/components/jsoncpp/include/json/features.h index 1bb7bb614868..de45248fb314 100644 --- a/toolkit/components/jsoncpp/include/json/features.h +++ b/toolkit/components/jsoncpp/include/json/features.h @@ -10,6 +10,8 @@ #include "forwards.h" #endif // if !defined(JSON_IS_AMALGAMATION) +#pragma pack(push, 8) + namespace Json { /** \brief Configuration passed to reader and writer. @@ -54,4 +56,6 @@ public: } // namespace Json +#pragma pack(pop) + #endif // CPPTL_JSON_FEATURES_H_INCLUDED diff --git a/toolkit/components/jsoncpp/include/json/reader.h b/toolkit/components/jsoncpp/include/json/reader.h index caf872737849..6ab5bdbf799b 100644 --- a/toolkit/components/jsoncpp/include/json/reader.h +++ b/toolkit/components/jsoncpp/include/json/reader.h @@ -23,6 +23,8 @@ #pragma warning(disable : 4251) #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) +#pragma pack(push, 8) + namespace Json { /** \brief Unserialize a JSON document into a @@ -397,6 +399,8 @@ JSON_API JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM&, Value&); } // namespace Json +#pragma pack(pop) + #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) #pragma warning(pop) #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) diff --git a/toolkit/components/jsoncpp/include/json/value.h b/toolkit/components/jsoncpp/include/json/value.h index fb88c1829519..c39f423fa5ad 100644 --- a/toolkit/components/jsoncpp/include/json/value.h +++ b/toolkit/components/jsoncpp/include/json/value.h @@ -42,6 +42,8 @@ #pragma warning(disable : 4251) #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) +#pragma pack(push, 8) + /** \brief JSON (JavaScript Object Notation). */ namespace Json { @@ -53,8 +55,8 @@ namespace Json { class JSON_API Exception : public std::exception { public: Exception(JSONCPP_STRING const& msg); - ~Exception() throw() JSONCPP_OVERRIDE; - char const* what() const throw() JSONCPP_OVERRIDE; + ~Exception() JSONCPP_NOEXCEPT JSONCPP_OVERRIDE; + char const* what() const JSONCPP_NOEXCEPT JSONCPP_OVERRIDE; protected: JSONCPP_STRING msg_; }; @@ -859,6 +861,7 @@ template<> inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); } } +#pragma pack(pop) #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) #pragma warning(pop) diff --git a/toolkit/components/jsoncpp/include/json/version.h b/toolkit/components/jsoncpp/include/json/version.h index 24e2b0903387..9e5a66ee6e51 100644 --- a/toolkit/components/jsoncpp/include/json/version.h +++ b/toolkit/components/jsoncpp/include/json/version.h @@ -3,10 +3,10 @@ #ifndef JSON_VERSION_H_INCLUDED # define JSON_VERSION_H_INCLUDED -# define JSONCPP_VERSION_STRING "1.7.7" +# define JSONCPP_VERSION_STRING "1.8.0" # define JSONCPP_VERSION_MAJOR 1 -# define JSONCPP_VERSION_MINOR 7 -# define JSONCPP_VERSION_PATCH 7 +# define JSONCPP_VERSION_MINOR 8 +# define JSONCPP_VERSION_PATCH 0 # define JSONCPP_VERSION_QUALIFIER # define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8)) diff --git a/toolkit/components/jsoncpp/include/json/writer.h b/toolkit/components/jsoncpp/include/json/writer.h index 2c1e65bf16f8..d0944eeb88c2 100644 --- a/toolkit/components/jsoncpp/include/json/writer.h +++ b/toolkit/components/jsoncpp/include/json/writer.h @@ -20,6 +20,8 @@ #pragma warning(disable : 4251) #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) +#pragma pack(push, 8) + namespace Json { class Value; @@ -324,6 +326,8 @@ JSON_API JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root); } // namespace Json +#pragma pack(pop) + #if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) #pragma warning(pop) #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) diff --git a/toolkit/components/jsoncpp/src/lib_json/json_reader.cpp b/toolkit/components/jsoncpp/src/lib_json/json_reader.cpp index 5e04d7447c27..ec7907525dfb 100644 --- a/toolkit/components/jsoncpp/src/lib_json/json_reader.cpp +++ b/toolkit/components/jsoncpp/src/lib_json/json_reader.cpp @@ -1,4 +1,5 @@ // Copyright 2007-2011 Baptiste Lepilleur +// Copyright (C) 2016 InfoTeCS JSC. All rights reserved. // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE @@ -44,8 +45,12 @@ #pragma warning(disable : 4996) #endif -static int const stackLimit_g = 1000; -static int stackDepth_g = 0; // see readValue() +// Define JSONCPP_DEPRECATED_STACK_LIMIT as an appropriate integer at compile time to change the stack limit +#if !defined(JSONCPP_DEPRECATED_STACK_LIMIT) +#define JSONCPP_DEPRECATED_STACK_LIMIT 1000 +#endif + +static size_t const stackLimit_g = JSONCPP_DEPRECATED_STACK_LIMIT; // see readValue() namespace Json { @@ -132,13 +137,12 @@ bool Reader::parse(const char* beginDoc, current_ = begin_; lastValueEnd_ = 0; lastValue_ = 0; - commentsBefore_ = ""; + commentsBefore_.clear(); errors_.clear(); while (!nodes_.empty()) nodes_.pop(); nodes_.push(&root); - stackDepth_g = 0; // Yes, this is bad coding, but options are limited. bool successful = readValue(); Token token; skipCommentTokens(token); @@ -161,12 +165,10 @@ bool Reader::parse(const char* beginDoc, } bool Reader::readValue() { - // This is a non-reentrant way to support a stackLimit. Terrible! - // But this deprecated class has a security problem: Bad input can - // cause a seg-fault. This seems like a fair, binary-compatible way - // to prevent the problem. - if (stackDepth_g >= stackLimit_g) throwRuntimeError("Exceeded stackLimit in readValue()."); - ++stackDepth_g; + // readValue() may call itself only if it calls readObject() or ReadArray(). + // These methods execute nodes_.push() just before and nodes_.pop)() just after calling readValue(). + // parse() executes one nodes_.push(), so > instead of >=. + if (nodes_.size() > stackLimit_g) throwRuntimeError("Exceeded stackLimit in readValue()."); Token token; skipCommentTokens(token); @@ -174,7 +176,7 @@ bool Reader::readValue() { if (collectComments_ && !commentsBefore_.empty()) { currentValue().setComment(commentsBefore_, commentBefore); - commentsBefore_ = ""; + commentsBefore_.clear(); } switch (token.type_) { @@ -240,7 +242,6 @@ bool Reader::readValue() { lastValue_ = ¤tValue(); } - --stackDepth_g; return successful; } @@ -473,7 +474,7 @@ bool Reader::readObject(Token& tokenStart) { break; if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object return true; - name = ""; + name.clear(); if (tokenName.type_ == tokenString) { if (!decodeString(tokenName, name)) return recoverFromError(tokenObjectEnd); @@ -1028,7 +1029,6 @@ private: Location lastValueEnd_; Value* lastValue_; JSONCPP_STRING commentsBefore_; - int stackDepth_; OurFeatures const features_; bool collectComments_; @@ -1039,7 +1039,6 @@ private: OurReader::OurReader(OurFeatures const& features) : errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(), lastValue_(), commentsBefore_(), - stackDepth_(0), features_(features), collectComments_() { } @@ -1057,13 +1056,12 @@ bool OurReader::parse(const char* beginDoc, current_ = begin_; lastValueEnd_ = 0; lastValue_ = 0; - commentsBefore_ = ""; + commentsBefore_.clear(); errors_.clear(); while (!nodes_.empty()) nodes_.pop(); nodes_.push(&root); - stackDepth_ = 0; bool successful = readValue(); Token token; skipCommentTokens(token); @@ -1092,15 +1090,15 @@ bool OurReader::parse(const char* beginDoc, } bool OurReader::readValue() { - if (stackDepth_ >= features_.stackLimit_) throwRuntimeError("Exceeded stackLimit in readValue()."); - ++stackDepth_; + // To preserve the old behaviour we cast size_t to int. + if (static_cast(nodes_.size()) > features_.stackLimit_) throwRuntimeError("Exceeded stackLimit in readValue()."); Token token; skipCommentTokens(token); bool successful = true; if (collectComments_ && !commentsBefore_.empty()) { currentValue().setComment(commentsBefore_, commentBefore); - commentsBefore_ = ""; + commentsBefore_.clear(); } switch (token.type_) { @@ -1190,7 +1188,6 @@ bool OurReader::readValue() { lastValue_ = ¤tValue(); } - --stackDepth_; return successful; } @@ -1450,7 +1447,7 @@ bool OurReader::readObject(Token& tokenStart) { break; if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object return true; - name = ""; + name.clear(); if (tokenName.type_ == tokenString) { if (!decodeString(tokenName, name)) return recoverFromError(tokenObjectEnd); diff --git a/toolkit/components/jsoncpp/src/lib_json/json_tool.h b/toolkit/components/jsoncpp/src/lib_json/json_tool.h index 0e729e63747d..41d0f49d2189 100644 --- a/toolkit/components/jsoncpp/src/lib_json/json_tool.h +++ b/toolkit/components/jsoncpp/src/lib_json/json_tool.h @@ -6,7 +6,13 @@ #ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED #define LIB_JSONCPP_JSON_TOOL_H_INCLUDED -#ifndef NO_LOCALE_SUPPORT + +// Also support old flag NO_LOCALE_SUPPORT +#ifdef NO_LOCALE_SUPPORT +#define JSONCPP_NO_LOCALE_SUPPORT +#endif + +#ifndef JSONCPP_NO_LOCALE_SUPPORT #include #endif @@ -18,7 +24,7 @@ namespace Json { static char getDecimalPoint() { -#ifdef NO_LOCALE_SUPPORT +#ifdef JSONCPP_NO_LOCALE_SUPPORT return '\0'; #else struct lconv* lc = localeconv(); diff --git a/toolkit/components/jsoncpp/src/lib_json/json_value.cpp b/toolkit/components/jsoncpp/src/lib_json/json_value.cpp index 88c630fdd21f..dc129645a71f 100644 --- a/toolkit/components/jsoncpp/src/lib_json/json_value.cpp +++ b/toolkit/components/jsoncpp/src/lib_json/json_value.cpp @@ -193,9 +193,9 @@ namespace Json { Exception::Exception(JSONCPP_STRING const& msg) : msg_(msg) {} -Exception::~Exception() throw() +Exception::~Exception() JSONCPP_NOEXCEPT {} -char const* Exception::what() const throw() +char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); } @@ -303,7 +303,7 @@ bool Value::CZString::operator<(const CZString& other) const { // Assume both are strings. unsigned this_len = this->storage_.length_; unsigned other_len = other.storage_.length_; - unsigned min_len = std::min(this_len, other_len); + unsigned min_len = std::min(this_len, other_len); JSON_ASSERT(this->cstr_ && other.cstr_); int comp = memcmp(this->cstr_, other.cstr_, min_len); if (comp < 0) return true; @@ -343,7 +343,7 @@ bool Value::CZString::isStaticString() const { return storage_.policy_ == noDupl * This optimization is used in ValueInternalMap fast allocator. */ Value::Value(ValueType vtype) { - static char const empty[] = ""; + static char const emptyString[] = ""; initBasic(vtype); switch (vtype) { case nullValue: @@ -357,7 +357,7 @@ Value::Value(ValueType vtype) { break; case stringValue: // allocated_ == false, so this is safe. - value_.string_ = const_cast(static_cast(empty)); + value_.string_ = const_cast(static_cast(emptyString)); break; case arrayValue: case objectValue: @@ -398,6 +398,7 @@ Value::Value(double value) { Value::Value(const char* value) { initBasic(stringValue, true); + JSON_ASSERT_MESSAGE(value != NULL, "Null Value Passed to Value Constructor"); value_.string_ = duplicateAndPrefixStringValue(value, static_cast(strlen(value))); } @@ -566,7 +567,7 @@ bool Value::operator<(const Value& other) const { char const* other_str; decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str); decodePrefixedString(other.allocated_, other.value_.string_, &other_len, &other_str); - unsigned min_len = std::min(this_len, other_len); + unsigned min_len = std::min(this_len, other_len); JSON_ASSERT(this_str && other_str); int comp = memcmp(this_str, other_str, min_len); if (comp < 0) return true; @@ -879,7 +880,7 @@ bool Value::isConvertibleTo(ValueType other) const { case nullValue: return (isNumeric() && asDouble() == 0.0) || (type_ == booleanValue && value_.bool_ == false) || - (type_ == stringValue && asString() == "") || + (type_ == stringValue && asString().empty()) || (type_ == arrayValue && value_.map_->size() == 0) || (type_ == objectValue && value_.map_->size() == 0) || type_ == nullValue; @@ -1279,7 +1280,11 @@ bool Value::isBool() const { return type_ == booleanValue; } bool Value::isInt() const { switch (type_) { case intValue: +#if defined(JSON_HAS_INT64) return value_.int_ >= minInt && value_.int_ <= maxInt; +#else + return true; +#endif case uintValue: return value_.uint_ <= UInt(maxInt); case realValue: @@ -1294,9 +1299,17 @@ bool Value::isInt() const { bool Value::isUInt() const { switch (type_) { case intValue: +#if defined(JSON_HAS_INT64) return value_.int_ >= 0 && LargestUInt(value_.int_) <= LargestUInt(maxUInt); +#else + return value_.int_ >= 0; +#endif case uintValue: +#if defined(JSON_HAS_INT64) return value_.uint_ <= maxUInt; +#else + return true; +#endif case realValue: return value_.real_ >= 0 && value_.real_ <= maxUInt && IsIntegral(value_.real_); @@ -1347,16 +1360,28 @@ bool Value::isUInt64() const { } bool Value::isIntegral() const { + switch (type_) { + case intValue: + case uintValue: + return true; + case realValue: #if defined(JSON_HAS_INT64) - return isInt64() || isUInt64(); + // Note that maxUInt64 (= 2^64 - 1) is not exactly representable as a + // double, so double(maxUInt64) will be rounded up to 2^64. Therefore we + // require the value to be strictly less than the limit. + return value_.real_ >= double(minInt64) && value_.real_ < maxUInt64AsDouble && IsIntegral(value_.real_); #else - return isInt() || isUInt(); -#endif + return value_.real_ >= minInt && value_.real_ <= maxUInt && IsIntegral(value_.real_); +#endif // JSON_HAS_INT64 + default: + break; + } + return false; } -bool Value::isDouble() const { return type_ == realValue || isIntegral(); } +bool Value::isDouble() const { return type_ == intValue || type_ == uintValue || type_ == realValue; } -bool Value::isNumeric() const { return isIntegral() || isDouble(); } +bool Value::isNumeric() const { return isDouble(); } bool Value::isString() const { return type_ == stringValue; } @@ -1481,6 +1506,7 @@ Path::Path(const JSONCPP_STRING& path, const PathArgument& a4, const PathArgument& a5) { InArgs in; + in.reserve(5); in.push_back(&a1); in.push_back(&a2); in.push_back(&a3); diff --git a/toolkit/components/jsoncpp/src/lib_json/json_writer.cpp b/toolkit/components/jsoncpp/src/lib_json/json_writer.cpp index 1bb3b21826ed..2ab16acbf746 100644 --- a/toolkit/components/jsoncpp/src/lib_json/json_writer.cpp +++ b/toolkit/components/jsoncpp/src/lib_json/json_writer.cpp @@ -139,17 +139,23 @@ namespace { JSONCPP_STRING valueToString(double value, bool useSpecialFloats, unsigned int precision) { // Allocate a buffer that is more than large enough to store the 16 digits of // precision requested below. - char buffer[32]; + char buffer[36]; int len = -1; - char formatString[6]; - sprintf(formatString, "%%.%dg", precision); + char formatString[15]; + snprintf(formatString, sizeof(formatString), "%%.%dg", precision); // Print into the buffer. We need not request the alternative representation // that always has a decimal point because JSON doesn't distingish the // concepts of reals and integers. if (isfinite(value)) { len = snprintf(buffer, sizeof(buffer), formatString, value); + + // try to ensure we preserve the fact that this was given to us as a double on input + if (!strstr(buffer, ".") && !strstr(buffer, "e")) { + strcat(buffer, ".0"); + } + } else { // IEEE standard states that NaN values will not compare to themselves if (value != value) { @@ -329,7 +335,7 @@ void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; } void FastWriter::omitEndingLineFeed() { omitEndingLineFeed_ = true; } JSONCPP_STRING FastWriter::write(const Value& root) { - document_ = ""; + document_.clear(); writeValue(root); if (!omitEndingLineFeed_) document_ += "\n"; @@ -397,9 +403,9 @@ StyledWriter::StyledWriter() : rightMargin_(74), indentSize_(3), addChildValues_() {} JSONCPP_STRING StyledWriter::write(const Value& root) { - document_ = ""; + document_.clear(); addChildValues_ = false; - indentString_ = ""; + indentString_.clear(); writeCommentBeforeValue(root); writeValue(root); writeCommentAfterValueOnSameLine(root); @@ -613,7 +619,7 @@ StyledStreamWriter::StyledStreamWriter(JSONCPP_STRING indentation) void StyledStreamWriter::write(JSONCPP_OSTREAM& out, const Value& root) { document_ = &out; addChildValues_ = false; - indentString_ = ""; + indentString_.clear(); indented_ = true; writeCommentBeforeValue(root); if (!indented_) writeIndent(); @@ -895,7 +901,7 @@ int BuiltStyledStreamWriter::write(Value const& root, JSONCPP_OSTREAM* sout) sout_ = sout; addChildValues_ = false; indented_ = true; - indentString_ = ""; + indentString_.clear(); writeCommentBeforeValue(root); if (!indented_) writeIndent(); indented_ = true; @@ -1149,10 +1155,10 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const } JSONCPP_STRING nullSymbol = "null"; if (dnp) { - nullSymbol = ""; + nullSymbol.clear(); } if (pre > 17) pre = 17; - JSONCPP_STRING endingLineFeedSymbol = ""; + JSONCPP_STRING endingLineFeedSymbol; return new BuiltStyledStreamWriter( indentation, cs, colonSymbol, nullSymbol, endingLineFeedSymbol, usf, pre);