1136 Commits

Author SHA1 Message Date
Konstantin Käfer
16872af889 Avoid pointer arithmetic on null pointer to remove undefined behavior
The existing checks triggered undefined behavior when the stack was empty (null pointer). This change avoid this:
* If `stackTop_` and `stackEnd_` are null, it results in a `ptrdiff_t` of `0`
* If `stackTop_` and `stackEnd_` are valid pointers, they produce a `ptrdiff_t` with the remaining size on the stack
2018-10-05 09:26:20 +02:00
Milo Yip
783b819e67
Update rapidjson.h 2018-09-10 13:11:17 +08:00
Milo Yip
8a96a95de2
Merge branch 'master' into fix-noexcept 2018-09-10 11:27:45 +08:00
Milo Yip
08b1a8a41e
Merge pull request #1302 from chwarr/min-max-guard
Guard against min/max being macros in reader.h
2018-09-10 11:22:28 +08:00
Milo Yip
81af404b7f
Merge pull request #1284 from mobileben/noexcept-assert
Handle non-throwing exception specifications that can still throw #1280
2018-09-10 11:21:34 +08:00
Lele Gaifax
11defb7aa4 Wrap all WriteXxx() calls within EndValue(), to ensure a flush after root-level scalar value
This attempts to fix issue #1336.
2018-08-03 12:17:29 +02:00
Milo Yip
6a905f9311
Merge pull request #1331 from JPEWdev/mem-alignment-fix
Fix SIGBUS due to unaligned access
2018-08-01 11:56:25 +08:00
IceTrailer
cd28248611 Fixed parentheses in reader.h which were required to prevent the using of max macro 2018-07-31 22:23:53 +02:00
Veselin Georgiev
748a652f04 Fix SIGBUS due to unaligned access
Update RAPIDJSON_ALIGN() to always align on an 8-byte boundary
unless otherwise overridden.

On some platforms (such as ARM), 64-bit items (such as doubles and
64-bit integers) must be aligned to an 8 byte address, even though the
architecture is only 32-bits. On these platforms, MemoryPoolAllocator
must match the malloc() behavior and return a 8 byte aligned allocation.
This eliminates any alignment issues that may occur at the expense of
additional memory overhead.

Failure to do so caused a SIGBUS signal when calling
GenericValue::SetNull(). The size of the data_ member of the
GenericValue class is 16 bytes in 32-bit mode and its constructor
requires an 8-byte aligned access.

While parsing a JSON formatted string using Document::ParseStream(), a
stack object containing GenericValue items was constructed. Since the
stack was 8-byte aligned, the constructor calls would succeed. When the
lifetime of the object ends, SetObjectRaw() is invoked. This triggered
an allocation with 4-byte alignment to which the previously 8-byte
aligned GenericValue array was copied. After this, any call to a
GenericValue API that triggered the constructor and thus the placement
new operation on the Data type member would trigger a SIGBUS.

Signed-off-by: Veselin Georgiev <veselin.georgiev@garmin.com>
Signed-off-by: Joshua Watt <Joshua.Watt@garmin.com>
2018-07-31 09:02:26 -05:00
Philipp A Hartmann
f54f6b5aa9 Add RAPIDJSON_NOEXCEPT_ASSERT
This is an alternative implementation to #1284 to handle
asserts in noexcept contexts.

Closes #1280.
2018-07-18 12:02:24 +02:00
Philipp A Hartmann
a26267d16d Fix -Wsign-conversion warnings/errors
GCC 8 (incorrectly) warns about sign conversions in (constant)
array size expressions:

error: conversion to 'long unsigned int' from 'int' may
change the sign of the result [-Werror=sign-conversion]
     char schemaBuffer_[128 * 1024];

Make these expressions unsigned by adding a 'u' suffix to
the first operands.
2018-07-15 16:01:02 +02:00
Philipp A Hartmann
fa5963a2f5 Fix -Wclass-memaccess warnings/errors
Recent GCC versions warn about using memcpy/memmove to
write to a class pointer (-Wclass-memaccess).

Avoid the warnings by casting to void* first.

Closes #1086.
Closes #1205.
Closes #1246.
2018-07-15 14:20:38 +02:00
Yolan Romailler
93331cb0cd Removing always true if condition 2018-07-12 15:13:19 +02:00
Christopher Warrington
960b9cfd19 Guard against min/max being macros in reader.h
Sometimes, particularly when Microsoft's windows.h is included, min/max
are defined as macros, interfering with use of
std::numeric_limits::min() and the like.

To guard against this, the function name is wrapped in an extra set of
parenthesis, which inhibits function-style macro expansion.

This is a similar commit to 6e38649ec6, but fixes uses of
std::numeric_limits added after that commit, like those introduced in
2ea43433e2.
2018-07-10 11:08:41 -07:00
Erik Froseth
3e255af03a Detect C++11 features for Developer Studio
This patch enables various C++11 features if the code is compiled with
Developer Studio compiler version 5.14 or higher.
2018-07-03 13:02:45 +02:00
Romain Moret
4595cc488e Rename a few internal preprocessor macros to avoid potential naming conflicts 2018-07-02 13:24:18 +02:00
Milo Yip
c511ce303f
Merge pull request #1250 from StilesCrisis/issue-1249-test
Unit Test: Parsing "0e100" in full precision mode causes UB
2018-06-18 23:54:53 +08:00
abolz
879ae853fe Fix offset computation in BigInteger::operator<< 2018-06-16 09:41:04 +02:00
abolz
a2813b6739 Limit exponents 2018-06-15 17:10:36 +02:00
abolz
6cd5cd7b94 [Debug - Initialize variable] 2018-06-15 16:01:52 +02:00
abolz
695c9cb976 Use C macros with the correct header instead of std::numeric_limits and static_cast
=D
2018-06-15 14:06:14 +02:00
abolz
1d636de81e Fix another signed/unsigned warning 2018-06-15 13:53:48 +02:00
abolz
a2a7d97b3b Use std::numeric_limits instead of macros 2018-06-15 13:50:19 +02:00
abolz
fc85fbeef0 Fix implicit signed/unsigned conversion and a small glitch in the error computation - part 2 2018-06-15 13:44:43 +02:00
abolz
16c97cd7c5 Fix implicit signed/unsigned conversion and a small glitch in the error computation 2018-06-15 13:44:15 +02:00
abolz
2ea43433e2 Fix bogus gcc warning 2018-06-15 13:41:44 +02:00
abolz
cb009f3050 Return infinity if binary exponent is too large 2018-06-15 12:59:05 +02:00
abolz
4e9b4f6d6a Return 0 if binary exponent is too small 2018-06-15 11:32:32 +02:00
abolz
f5e5d47fac Properly test for overflow
Do not use an approximation to do this. Instead check if the result is Inf.
2018-06-15 11:29:48 +02:00
abolz
d83d2ba260 Trim all zeros from input
If the buffer only contains zeros, return 0.
2018-06-15 10:46:45 +02:00
abolz
c59ecc857d Replace unsigned with signed integer arithmetic in strtod 2018-06-15 10:44:10 +02:00
abolz
29b6c9b7dc Add assertions to check preconditions of functions and unsigned integer arithmetic 2018-06-15 10:35:31 +02:00
Marian Klymov
2b0843037e Autodetect RAPIDJSON_HAS_CXX11_NOEXCEPT and RAPIDJSON_HAS_CXX11_TYPETRAITS for Visual Studio 2018-06-13 20:43:16 +03:00
Benjamin Lee
5b0610a74f Handle non-throwing exception specifications that can still throw #1280 2018-06-06 23:34:51 -07:00
bogaotory
6f7dcb30d9 again, in relation to solving issue #784, use SizeType-typed variable to indicate a none-zero length string has been given in the schema as default value for the json property; added an unittest Object_Required_PassWithDefault 2018-06-01 21:16:26 +01:00
bogaotory
fa98b5b4b6 in relation to solving issue #784, this commit enables the schema to recognise the "default" property, and avoids a missing property error when a default is given in the schema 2018-06-01 11:07:53 +01:00
Florin Malita
8269bc2bc2 Prevent int underflow when parsing exponents
When parsing negative exponents, the current implementation takes
precautions for |exp| to not underflow int.

But that is not sufficient: later on [1], |exp + expFrac| is also
stored to an int - so we must ensure that the sum stays within int
representable values.

Update the exp clamping logic to take expFrac into account.

[1] https://github.com/Tencent/rapidjson/blob/master/include/rapidjson/reader.h#L1690
2018-05-15 22:48:07 -04:00
John Stiles
f7d2cd2228 added test for parsing 0e100 2018-05-11 15:16:46 -07:00
Milo Yip
a091035846
Merge pull request #1240 from ksergey/FIX_Reader
Added const for Reader methods
2018-05-04 10:11:59 +08:00
Sergey Kovalevich
d0a78bf56e Added const for Reader methods 2018-05-03 15:11:16 +03:00
Milo Yip
b32cd9421c
Merge pull request #1217 from tresorit/win-clang-fix
Fix compilation on windows with clang
2018-04-25 10:13:55 +08:00
Stephen Kelly
73b8774ab1
Use rvalue refs with clang-cl 2018-04-24 22:55:47 +01:00
Ryan Morris
6f587466a1 Added macro RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY to allow default chunk capacity to be lowered for embedded devices with < 64k stack sizes 2018-04-17 12:53:23 -07:00
Zoltan Kovago
0fdd8040ce fix compilation on windows with clang 2018-04-09 15:47:17 +02:00
Christian Semmler
8a6c345bcc add remote ref to schemaMap_ 2018-03-23 23:33:20 +01:00
John
de6681e295 ensure the pragma is only applied to MSVC 2018-03-19 15:18:08 -04:00
sergey kachanovskiy
2e5dcceda0 Fixes #1198 2018-03-12 16:11:09 +01:00
MaximeBF
294a5aca8f Support long and unsined long as int and unsigned on Microsft platforms 2018-03-06 11:17:04 -05:00
maficccc@gmail.com
72481d5a04 Fix warnings Dereference of null pointer 2018-03-03 00:08:11 +01:00
Milo Yip
9dfc437477
Merge pull request #1182 from Romain-Geissler-1A/ignore-gcc-8-warnings
Ignore GCC 8 warnings.
2018-02-22 09:24:02 +08:00