Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
8bf4f7b9
Unverified
Commit
8bf4f7b9
authored
Mar 04, 2018
by
Milo Yip
Committed by
GitHub
Mar 04, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1188 from Martinfx/master
Fix warnings: dereference of null pointer
parents
9dfc4374
72481d5a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
37 deletions
+42
-37
itoa.h
include/rapidjson/internal/itoa.h
+42
-37
No files found.
include/rapidjson/internal/itoa.h
View file @
8bf4f7b9
// 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.
//
// Licensed under the MIT License (the "License"); you may not use this file except
...
...
@@ -7,9 +7,9 @@
//
// http://opensource.org/licenses/MIT
//
// 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
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// 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
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
#ifndef RAPIDJSON_ITOA_
...
...
@@ -37,12 +37,14 @@ inline const char* GetDigitsLut() {
}
inline
char
*
u32toa
(
uint32_t
value
,
char
*
buffer
)
{
RAPIDJSON_ASSERT
(
buffer
!=
0
);
const
char
*
cDigitsLut
=
GetDigitsLut
();
if
(
value
<
10000
)
{
const
uint32_t
d1
=
(
value
/
100
)
<<
1
;
const
uint32_t
d2
=
(
value
%
100
)
<<
1
;
if
(
value
>=
1000
)
*
buffer
++
=
cDigitsLut
[
d1
];
if
(
value
>=
100
)
...
...
@@ -55,13 +57,13 @@ inline char* u32toa(uint32_t value, char* buffer) {
// value = bbbbcccc
const
uint32_t
b
=
value
/
10000
;
const
uint32_t
c
=
value
%
10000
;
const
uint32_t
d1
=
(
b
/
100
)
<<
1
;
const
uint32_t
d2
=
(
b
%
100
)
<<
1
;
const
uint32_t
d3
=
(
c
/
100
)
<<
1
;
const
uint32_t
d4
=
(
c
%
100
)
<<
1
;
if
(
value
>=
10000000
)
*
buffer
++
=
cDigitsLut
[
d1
];
if
(
value
>=
1000000
)
...
...
@@ -69,7 +71,7 @@ inline char* u32toa(uint32_t value, char* buffer) {
if
(
value
>=
100000
)
*
buffer
++
=
cDigitsLut
[
d2
];
*
buffer
++
=
cDigitsLut
[
d2
+
1
];
*
buffer
++
=
cDigitsLut
[
d3
];
*
buffer
++
=
cDigitsLut
[
d3
+
1
];
*
buffer
++
=
cDigitsLut
[
d4
];
...
...
@@ -77,10 +79,10 @@ inline char* u32toa(uint32_t value, char* buffer) {
}
else
{
// value = aabbbbcccc in decimal
const
uint32_t
a
=
value
/
100000000
;
// 1 to 42
value
%=
100000000
;
if
(
a
>=
10
)
{
const
unsigned
i
=
a
<<
1
;
*
buffer
++
=
cDigitsLut
[
i
];
...
...
@@ -91,13 +93,13 @@ inline char* u32toa(uint32_t value, char* buffer) {
const
uint32_t
b
=
value
/
10000
;
// 0 to 9999
const
uint32_t
c
=
value
%
10000
;
// 0 to 9999
const
uint32_t
d1
=
(
b
/
100
)
<<
1
;
const
uint32_t
d2
=
(
b
%
100
)
<<
1
;
const
uint32_t
d3
=
(
c
/
100
)
<<
1
;
const
uint32_t
d4
=
(
c
%
100
)
<<
1
;
*
buffer
++
=
cDigitsLut
[
d1
];
*
buffer
++
=
cDigitsLut
[
d1
+
1
];
*
buffer
++
=
cDigitsLut
[
d2
];
...
...
@@ -111,6 +113,7 @@ inline char* u32toa(uint32_t value, char* buffer) {
}
inline
char
*
i32toa
(
int32_t
value
,
char
*
buffer
)
{
RAPIDJSON_ASSERT
(
buffer
!=
0
);
uint32_t
u
=
static_cast
<
uint32_t
>
(
value
);
if
(
value
<
0
)
{
*
buffer
++
=
'-'
;
...
...
@@ -121,6 +124,7 @@ inline char* i32toa(int32_t value, char* buffer) {
}
inline
char
*
u64toa
(
uint64_t
value
,
char
*
buffer
)
{
RAPIDJSON_ASSERT
(
buffer
!=
0
);
const
char
*
cDigitsLut
=
GetDigitsLut
();
const
uint64_t
kTen8
=
100000000
;
const
uint64_t
kTen9
=
kTen8
*
10
;
...
...
@@ -131,13 +135,13 @@ inline char* u64toa(uint64_t value, char* buffer) {
const
uint64_t
kTen14
=
kTen8
*
1000000
;
const
uint64_t
kTen15
=
kTen8
*
10000000
;
const
uint64_t
kTen16
=
kTen8
*
kTen8
;
if
(
value
<
kTen8
)
{
uint32_t
v
=
static_cast
<
uint32_t
>
(
value
);
if
(
v
<
10000
)
{
const
uint32_t
d1
=
(
v
/
100
)
<<
1
;
const
uint32_t
d2
=
(
v
%
100
)
<<
1
;
if
(
v
>=
1000
)
*
buffer
++
=
cDigitsLut
[
d1
];
if
(
v
>=
100
)
...
...
@@ -150,13 +154,13 @@ inline char* u64toa(uint64_t value, char* buffer) {
// value = bbbbcccc
const
uint32_t
b
=
v
/
10000
;
const
uint32_t
c
=
v
%
10000
;
const
uint32_t
d1
=
(
b
/
100
)
<<
1
;
const
uint32_t
d2
=
(
b
%
100
)
<<
1
;
const
uint32_t
d3
=
(
c
/
100
)
<<
1
;
const
uint32_t
d4
=
(
c
%
100
)
<<
1
;
if
(
value
>=
10000000
)
*
buffer
++
=
cDigitsLut
[
d1
];
if
(
value
>=
1000000
)
...
...
@@ -164,7 +168,7 @@ inline char* u64toa(uint64_t value, char* buffer) {
if
(
value
>=
100000
)
*
buffer
++
=
cDigitsLut
[
d2
];
*
buffer
++
=
cDigitsLut
[
d2
+
1
];
*
buffer
++
=
cDigitsLut
[
d3
];
*
buffer
++
=
cDigitsLut
[
d3
+
1
];
*
buffer
++
=
cDigitsLut
[
d4
];
...
...
@@ -174,22 +178,22 @@ inline char* u64toa(uint64_t value, char* buffer) {
else
if
(
value
<
kTen16
)
{
const
uint32_t
v0
=
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
c0
=
v0
%
10000
;
const
uint32_t
d1
=
(
b0
/
100
)
<<
1
;
const
uint32_t
d2
=
(
b0
%
100
)
<<
1
;
const
uint32_t
d3
=
(
c0
/
100
)
<<
1
;
const
uint32_t
d4
=
(
c0
%
100
)
<<
1
;
const
uint32_t
b1
=
v1
/
10000
;
const
uint32_t
c1
=
v1
%
10000
;
const
uint32_t
d5
=
(
b1
/
100
)
<<
1
;
const
uint32_t
d6
=
(
b1
%
100
)
<<
1
;
const
uint32_t
d7
=
(
c1
/
100
)
<<
1
;
const
uint32_t
d8
=
(
c1
%
100
)
<<
1
;
...
...
@@ -209,7 +213,7 @@ inline char* u64toa(uint64_t value, char* buffer) {
*
buffer
++
=
cDigitsLut
[
d4
];
if
(
value
>=
kTen8
)
*
buffer
++
=
cDigitsLut
[
d4
+
1
];
*
buffer
++
=
cDigitsLut
[
d5
];
*
buffer
++
=
cDigitsLut
[
d5
+
1
];
*
buffer
++
=
cDigitsLut
[
d6
];
...
...
@@ -222,7 +226,7 @@ inline char* u64toa(uint64_t value, char* buffer) {
else
{
const
uint32_t
a
=
static_cast
<
uint32_t
>
(
value
/
kTen16
);
// 1 to 1844
value
%=
kTen16
;
if
(
a
<
10
)
*
buffer
++
=
static_cast
<
char
>
(
'0'
+
static_cast
<
char
>
(
a
));
else
if
(
a
<
100
)
{
...
...
@@ -232,7 +236,7 @@ inline char* u64toa(uint64_t value, char* buffer) {
}
else
if
(
a
<
1000
)
{
*
buffer
++
=
static_cast
<
char
>
(
'0'
+
static_cast
<
char
>
(
a
/
100
));
const
uint32_t
i
=
(
a
%
100
)
<<
1
;
*
buffer
++
=
cDigitsLut
[
i
];
*
buffer
++
=
cDigitsLut
[
i
+
1
];
...
...
@@ -245,28 +249,28 @@ inline char* u64toa(uint64_t value, char* buffer) {
*
buffer
++
=
cDigitsLut
[
j
];
*
buffer
++
=
cDigitsLut
[
j
+
1
];
}
const
uint32_t
v0
=
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
c0
=
v0
%
10000
;
const
uint32_t
d1
=
(
b0
/
100
)
<<
1
;
const
uint32_t
d2
=
(
b0
%
100
)
<<
1
;
const
uint32_t
d3
=
(
c0
/
100
)
<<
1
;
const
uint32_t
d4
=
(
c0
%
100
)
<<
1
;
const
uint32_t
b1
=
v1
/
10000
;
const
uint32_t
c1
=
v1
%
10000
;
const
uint32_t
d5
=
(
b1
/
100
)
<<
1
;
const
uint32_t
d6
=
(
b1
%
100
)
<<
1
;
const
uint32_t
d7
=
(
c1
/
100
)
<<
1
;
const
uint32_t
d8
=
(
c1
%
100
)
<<
1
;
*
buffer
++
=
cDigitsLut
[
d1
];
*
buffer
++
=
cDigitsLut
[
d1
+
1
];
*
buffer
++
=
cDigitsLut
[
d2
];
...
...
@@ -284,11 +288,12 @@ inline char* u64toa(uint64_t value, char* buffer) {
*
buffer
++
=
cDigitsLut
[
d8
];
*
buffer
++
=
cDigitsLut
[
d8
+
1
];
}
return
buffer
;
}
inline
char
*
i64toa
(
int64_t
value
,
char
*
buffer
)
{
RAPIDJSON_ASSERT
(
buffer
!=
0
);
uint64_t
u
=
static_cast
<
uint64_t
>
(
value
);
if
(
value
<
0
)
{
*
buffer
++
=
'-'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment