diff options
author | Milo Yip <miloyip@gmail.com> | 2016-03-01 20:01:17 +0300 |
---|---|---|
committer | Milo Yip <miloyip@gmail.com> | 2016-03-01 20:01:17 +0300 |
commit | 928caf92eda18f19b8833b0632c2ba6021dddb99 (patch) | |
tree | 6de98dff237003f685a05dc1db380158d5e5b823 /include/rapidjson/internal | |
parent | 6c927047c4bac980a38f9101c30dd01cfe6211c0 (diff) |
Fix gcc strict-overflow warning
Fix #566 #568
Diffstat (limited to 'include/rapidjson/internal')
-rw-r--r-- | include/rapidjson/internal/dtoa.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/include/rapidjson/internal/dtoa.h b/include/rapidjson/internal/dtoa.h index 940d61a0..eabf7e38 100644 --- a/include/rapidjson/internal/dtoa.h +++ b/include/rapidjson/internal/dtoa.h @@ -148,7 +148,7 @@ inline char* WriteExponent(int K, char* buffer) { inline char* Prettify(char* buffer, int length, int k, int maxDecimalPlaces) { const int kk = length + k; // 10^(kk-1) <= v < 10^kk - if (length <= kk && kk <= 21) { + if (0 <= k && kk <= 21) { // 1234e7 -> 12340000000 for (int i = length; i < kk; i++) buffer[i] = '0'; @@ -160,7 +160,7 @@ inline char* Prettify(char* buffer, int length, int k, int maxDecimalPlaces) { // 1234e-2 -> 12.34 std::memmove(&buffer[kk + 1], &buffer[kk], static_cast<size_t>(length - kk)); buffer[kk] = '.'; - if (length > kk + maxDecimalPlaces) { + if (0 > k + maxDecimalPlaces) { // When maxDecimalPlaces = 2, 1.2345 -> 1.23, 1.102 -> 1.1 // Remove extra trailing zeros (at least one) after truncation. for (int i = kk + maxDecimalPlaces; i > kk + 1; i--) |