Commit 72481d5a authored by maficccc@gmail.com's avatar maficccc@gmail.com

Fix warnings Dereference of null pointer

parent 9dfc4374
// Tencent is pleased to support the open source community by making RapidJSON available. // Tencent is pleased to support the open source community by making RapidJSON available.
// //
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
// //
// Licensed under the MIT License (the "License"); you may not use this file except // Licensed under the MIT License (the "License"); you may not use this file except
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
// //
// http://opensource.org/licenses/MIT // http://opensource.org/licenses/MIT
// //
// Unless required by applicable law or agreed to in writing, software distributed // Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the // CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License. // specific language governing permissions and limitations under the License.
#ifndef RAPIDJSON_ITOA_ #ifndef RAPIDJSON_ITOA_
...@@ -37,12 +37,14 @@ inline const char* GetDigitsLut() { ...@@ -37,12 +37,14 @@ inline const char* GetDigitsLut() {
} }
inline char* u32toa(uint32_t value, char* buffer) { inline char* u32toa(uint32_t value, char* buffer) {
RAPIDJSON_ASSERT(buffer != 0);
const char* cDigitsLut = GetDigitsLut(); const char* cDigitsLut = GetDigitsLut();
if (value < 10000) { if (value < 10000) {
const uint32_t d1 = (value / 100) << 1; const uint32_t d1 = (value / 100) << 1;
const uint32_t d2 = (value % 100) << 1; const uint32_t d2 = (value % 100) << 1;
if (value >= 1000) if (value >= 1000)
*buffer++ = cDigitsLut[d1]; *buffer++ = cDigitsLut[d1];
if (value >= 100) if (value >= 100)
...@@ -55,13 +57,13 @@ inline char* u32toa(uint32_t value, char* buffer) { ...@@ -55,13 +57,13 @@ inline char* u32toa(uint32_t value, char* buffer) {
// value = bbbbcccc // value = bbbbcccc
const uint32_t b = value / 10000; const uint32_t b = value / 10000;
const uint32_t c = value % 10000; const uint32_t c = value % 10000;
const uint32_t d1 = (b / 100) << 1; const uint32_t d1 = (b / 100) << 1;
const uint32_t d2 = (b % 100) << 1; const uint32_t d2 = (b % 100) << 1;
const uint32_t d3 = (c / 100) << 1; const uint32_t d3 = (c / 100) << 1;
const uint32_t d4 = (c % 100) << 1; const uint32_t d4 = (c % 100) << 1;
if (value >= 10000000) if (value >= 10000000)
*buffer++ = cDigitsLut[d1]; *buffer++ = cDigitsLut[d1];
if (value >= 1000000) if (value >= 1000000)
...@@ -69,7 +71,7 @@ inline char* u32toa(uint32_t value, char* buffer) { ...@@ -69,7 +71,7 @@ inline char* u32toa(uint32_t value, char* buffer) {
if (value >= 100000) if (value >= 100000)
*buffer++ = cDigitsLut[d2]; *buffer++ = cDigitsLut[d2];
*buffer++ = cDigitsLut[d2 + 1]; *buffer++ = cDigitsLut[d2 + 1];
*buffer++ = cDigitsLut[d3]; *buffer++ = cDigitsLut[d3];
*buffer++ = cDigitsLut[d3 + 1]; *buffer++ = cDigitsLut[d3 + 1];
*buffer++ = cDigitsLut[d4]; *buffer++ = cDigitsLut[d4];
...@@ -77,10 +79,10 @@ inline char* u32toa(uint32_t value, char* buffer) { ...@@ -77,10 +79,10 @@ inline char* u32toa(uint32_t value, char* buffer) {
} }
else { else {
// value = aabbbbcccc in decimal // value = aabbbbcccc in decimal
const uint32_t a = value / 100000000; // 1 to 42 const uint32_t a = value / 100000000; // 1 to 42
value %= 100000000; value %= 100000000;
if (a >= 10) { if (a >= 10) {
const unsigned i = a << 1; const unsigned i = a << 1;
*buffer++ = cDigitsLut[i]; *buffer++ = cDigitsLut[i];
...@@ -91,13 +93,13 @@ inline char* u32toa(uint32_t value, char* buffer) { ...@@ -91,13 +93,13 @@ inline char* u32toa(uint32_t value, char* buffer) {
const uint32_t b = value / 10000; // 0 to 9999 const uint32_t b = value / 10000; // 0 to 9999
const uint32_t c = value % 10000; // 0 to 9999 const uint32_t c = value % 10000; // 0 to 9999
const uint32_t d1 = (b / 100) << 1; const uint32_t d1 = (b / 100) << 1;
const uint32_t d2 = (b % 100) << 1; const uint32_t d2 = (b % 100) << 1;
const uint32_t d3 = (c / 100) << 1; const uint32_t d3 = (c / 100) << 1;
const uint32_t d4 = (c % 100) << 1; const uint32_t d4 = (c % 100) << 1;
*buffer++ = cDigitsLut[d1]; *buffer++ = cDigitsLut[d1];
*buffer++ = cDigitsLut[d1 + 1]; *buffer++ = cDigitsLut[d1 + 1];
*buffer++ = cDigitsLut[d2]; *buffer++ = cDigitsLut[d2];
...@@ -111,6 +113,7 @@ inline char* u32toa(uint32_t value, char* buffer) { ...@@ -111,6 +113,7 @@ inline char* u32toa(uint32_t value, char* buffer) {
} }
inline char* i32toa(int32_t value, char* buffer) { inline char* i32toa(int32_t value, char* buffer) {
RAPIDJSON_ASSERT(buffer != 0);
uint32_t u = static_cast<uint32_t>(value); uint32_t u = static_cast<uint32_t>(value);
if (value < 0) { if (value < 0) {
*buffer++ = '-'; *buffer++ = '-';
...@@ -121,6 +124,7 @@ inline char* i32toa(int32_t value, char* buffer) { ...@@ -121,6 +124,7 @@ inline char* i32toa(int32_t value, char* buffer) {
} }
inline char* u64toa(uint64_t value, char* buffer) { inline char* u64toa(uint64_t value, char* buffer) {
RAPIDJSON_ASSERT(buffer != 0);
const char* cDigitsLut = GetDigitsLut(); const char* cDigitsLut = GetDigitsLut();
const uint64_t kTen8 = 100000000; const uint64_t kTen8 = 100000000;
const uint64_t kTen9 = kTen8 * 10; const uint64_t kTen9 = kTen8 * 10;
...@@ -131,13 +135,13 @@ inline char* u64toa(uint64_t value, char* buffer) { ...@@ -131,13 +135,13 @@ inline char* u64toa(uint64_t value, char* buffer) {
const uint64_t kTen14 = kTen8 * 1000000; const uint64_t kTen14 = kTen8 * 1000000;
const uint64_t kTen15 = kTen8 * 10000000; const uint64_t kTen15 = kTen8 * 10000000;
const uint64_t kTen16 = kTen8 * kTen8; const uint64_t kTen16 = kTen8 * kTen8;
if (value < kTen8) { if (value < kTen8) {
uint32_t v = static_cast<uint32_t>(value); uint32_t v = static_cast<uint32_t>(value);
if (v < 10000) { if (v < 10000) {
const uint32_t d1 = (v / 100) << 1; const uint32_t d1 = (v / 100) << 1;
const uint32_t d2 = (v % 100) << 1; const uint32_t d2 = (v % 100) << 1;
if (v >= 1000) if (v >= 1000)
*buffer++ = cDigitsLut[d1]; *buffer++ = cDigitsLut[d1];
if (v >= 100) if (v >= 100)
...@@ -150,13 +154,13 @@ inline char* u64toa(uint64_t value, char* buffer) { ...@@ -150,13 +154,13 @@ inline char* u64toa(uint64_t value, char* buffer) {
// value = bbbbcccc // value = bbbbcccc
const uint32_t b = v / 10000; const uint32_t b = v / 10000;
const uint32_t c = v % 10000; const uint32_t c = v % 10000;
const uint32_t d1 = (b / 100) << 1; const uint32_t d1 = (b / 100) << 1;
const uint32_t d2 = (b % 100) << 1; const uint32_t d2 = (b % 100) << 1;
const uint32_t d3 = (c / 100) << 1; const uint32_t d3 = (c / 100) << 1;
const uint32_t d4 = (c % 100) << 1; const uint32_t d4 = (c % 100) << 1;
if (value >= 10000000) if (value >= 10000000)
*buffer++ = cDigitsLut[d1]; *buffer++ = cDigitsLut[d1];
if (value >= 1000000) if (value >= 1000000)
...@@ -164,7 +168,7 @@ inline char* u64toa(uint64_t value, char* buffer) { ...@@ -164,7 +168,7 @@ inline char* u64toa(uint64_t value, char* buffer) {
if (value >= 100000) if (value >= 100000)
*buffer++ = cDigitsLut[d2]; *buffer++ = cDigitsLut[d2];
*buffer++ = cDigitsLut[d2 + 1]; *buffer++ = cDigitsLut[d2 + 1];
*buffer++ = cDigitsLut[d3]; *buffer++ = cDigitsLut[d3];
*buffer++ = cDigitsLut[d3 + 1]; *buffer++ = cDigitsLut[d3 + 1];
*buffer++ = cDigitsLut[d4]; *buffer++ = cDigitsLut[d4];
...@@ -174,22 +178,22 @@ inline char* u64toa(uint64_t value, char* buffer) { ...@@ -174,22 +178,22 @@ inline char* u64toa(uint64_t value, char* buffer) {
else if (value < kTen16) { else if (value < kTen16) {
const uint32_t v0 = static_cast<uint32_t>(value / kTen8); const uint32_t v0 = static_cast<uint32_t>(value / kTen8);
const uint32_t v1 = static_cast<uint32_t>(value % kTen8); const uint32_t v1 = static_cast<uint32_t>(value % kTen8);
const uint32_t b0 = v0 / 10000; const uint32_t b0 = v0 / 10000;
const uint32_t c0 = v0 % 10000; const uint32_t c0 = v0 % 10000;
const uint32_t d1 = (b0 / 100) << 1; const uint32_t d1 = (b0 / 100) << 1;
const uint32_t d2 = (b0 % 100) << 1; const uint32_t d2 = (b0 % 100) << 1;
const uint32_t d3 = (c0 / 100) << 1; const uint32_t d3 = (c0 / 100) << 1;
const uint32_t d4 = (c0 % 100) << 1; const uint32_t d4 = (c0 % 100) << 1;
const uint32_t b1 = v1 / 10000; const uint32_t b1 = v1 / 10000;
const uint32_t c1 = v1 % 10000; const uint32_t c1 = v1 % 10000;
const uint32_t d5 = (b1 / 100) << 1; const uint32_t d5 = (b1 / 100) << 1;
const uint32_t d6 = (b1 % 100) << 1; const uint32_t d6 = (b1 % 100) << 1;
const uint32_t d7 = (c1 / 100) << 1; const uint32_t d7 = (c1 / 100) << 1;
const uint32_t d8 = (c1 % 100) << 1; const uint32_t d8 = (c1 % 100) << 1;
...@@ -209,7 +213,7 @@ inline char* u64toa(uint64_t value, char* buffer) { ...@@ -209,7 +213,7 @@ inline char* u64toa(uint64_t value, char* buffer) {
*buffer++ = cDigitsLut[d4]; *buffer++ = cDigitsLut[d4];
if (value >= kTen8) if (value >= kTen8)
*buffer++ = cDigitsLut[d4 + 1]; *buffer++ = cDigitsLut[d4 + 1];
*buffer++ = cDigitsLut[d5]; *buffer++ = cDigitsLut[d5];
*buffer++ = cDigitsLut[d5 + 1]; *buffer++ = cDigitsLut[d5 + 1];
*buffer++ = cDigitsLut[d6]; *buffer++ = cDigitsLut[d6];
...@@ -222,7 +226,7 @@ inline char* u64toa(uint64_t value, char* buffer) { ...@@ -222,7 +226,7 @@ inline char* u64toa(uint64_t value, char* buffer) {
else { else {
const uint32_t a = static_cast<uint32_t>(value / kTen16); // 1 to 1844 const uint32_t a = static_cast<uint32_t>(value / kTen16); // 1 to 1844
value %= kTen16; value %= kTen16;
if (a < 10) if (a < 10)
*buffer++ = static_cast<char>('0' + static_cast<char>(a)); *buffer++ = static_cast<char>('0' + static_cast<char>(a));
else if (a < 100) { else if (a < 100) {
...@@ -232,7 +236,7 @@ inline char* u64toa(uint64_t value, char* buffer) { ...@@ -232,7 +236,7 @@ inline char* u64toa(uint64_t value, char* buffer) {
} }
else if (a < 1000) { else if (a < 1000) {
*buffer++ = static_cast<char>('0' + static_cast<char>(a / 100)); *buffer++ = static_cast<char>('0' + static_cast<char>(a / 100));
const uint32_t i = (a % 100) << 1; const uint32_t i = (a % 100) << 1;
*buffer++ = cDigitsLut[i]; *buffer++ = cDigitsLut[i];
*buffer++ = cDigitsLut[i + 1]; *buffer++ = cDigitsLut[i + 1];
...@@ -245,28 +249,28 @@ inline char* u64toa(uint64_t value, char* buffer) { ...@@ -245,28 +249,28 @@ inline char* u64toa(uint64_t value, char* buffer) {
*buffer++ = cDigitsLut[j]; *buffer++ = cDigitsLut[j];
*buffer++ = cDigitsLut[j + 1]; *buffer++ = cDigitsLut[j + 1];
} }
const uint32_t v0 = static_cast<uint32_t>(value / kTen8); const uint32_t v0 = static_cast<uint32_t>(value / kTen8);
const uint32_t v1 = static_cast<uint32_t>(value % kTen8); const uint32_t v1 = static_cast<uint32_t>(value % kTen8);
const uint32_t b0 = v0 / 10000; const uint32_t b0 = v0 / 10000;
const uint32_t c0 = v0 % 10000; const uint32_t c0 = v0 % 10000;
const uint32_t d1 = (b0 / 100) << 1; const uint32_t d1 = (b0 / 100) << 1;
const uint32_t d2 = (b0 % 100) << 1; const uint32_t d2 = (b0 % 100) << 1;
const uint32_t d3 = (c0 / 100) << 1; const uint32_t d3 = (c0 / 100) << 1;
const uint32_t d4 = (c0 % 100) << 1; const uint32_t d4 = (c0 % 100) << 1;
const uint32_t b1 = v1 / 10000; const uint32_t b1 = v1 / 10000;
const uint32_t c1 = v1 % 10000; const uint32_t c1 = v1 % 10000;
const uint32_t d5 = (b1 / 100) << 1; const uint32_t d5 = (b1 / 100) << 1;
const uint32_t d6 = (b1 % 100) << 1; const uint32_t d6 = (b1 % 100) << 1;
const uint32_t d7 = (c1 / 100) << 1; const uint32_t d7 = (c1 / 100) << 1;
const uint32_t d8 = (c1 % 100) << 1; const uint32_t d8 = (c1 % 100) << 1;
*buffer++ = cDigitsLut[d1]; *buffer++ = cDigitsLut[d1];
*buffer++ = cDigitsLut[d1 + 1]; *buffer++ = cDigitsLut[d1 + 1];
*buffer++ = cDigitsLut[d2]; *buffer++ = cDigitsLut[d2];
...@@ -284,11 +288,12 @@ inline char* u64toa(uint64_t value, char* buffer) { ...@@ -284,11 +288,12 @@ inline char* u64toa(uint64_t value, char* buffer) {
*buffer++ = cDigitsLut[d8]; *buffer++ = cDigitsLut[d8];
*buffer++ = cDigitsLut[d8 + 1]; *buffer++ = cDigitsLut[d8 + 1];
} }
return buffer; return buffer;
} }
inline char* i64toa(int64_t value, char* buffer) { inline char* i64toa(int64_t value, char* buffer) {
RAPIDJSON_ASSERT(buffer != 0);
uint64_t u = static_cast<uint64_t>(value); uint64_t u = static_cast<uint64_t>(value);
if (value < 0) { if (value < 0) {
*buffer++ = '-'; *buffer++ = '-';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment