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
29b6c9b7
Commit
29b6c9b7
authored
Jun 15, 2018
by
abolz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add assertions to check preconditions of functions and unsigned integer arithmetic
parent
80dba56a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
4 deletions
+12
-4
diyfp.h
include/rapidjson/internal/diyfp.h
+9
-4
strtod.h
include/rapidjson/internal/strtod.h
+3
-0
No files found.
include/rapidjson/internal/diyfp.h
View file @
29b6c9b7
...
...
@@ -141,6 +141,9 @@ struct DiyFp {
double
d
;
uint64_t
u64
;
}
u
;
RAPIDJSON_ASSERT
(
f
<=
kDpHiddenBit
+
kDpSignificandMask
);
RAPIDJSON_ASSERT
(
e
>=
kDpDenormalExponent
);
RAPIDJSON_ASSERT
(
e
<
kDpMaxExponent
);
const
uint64_t
be
=
(
e
==
kDpDenormalExponent
&&
(
f
&
kDpHiddenBit
)
==
0
)
?
0
:
static_cast
<
uint64_t
>
(
e
+
kDpExponentBias
);
u
.
u64
=
(
f
&
kDpSignificandMask
)
|
(
be
<<
kDpSignificandSize
);
...
...
@@ -220,6 +223,7 @@ inline DiyFp GetCachedPowerByIndex(size_t index) {
641
,
667
,
694
,
720
,
747
,
774
,
800
,
827
,
853
,
880
,
907
,
933
,
960
,
986
,
1013
,
1039
,
1066
};
RAPIDJSON_ASSERT
(
index
<
87
);
return
DiyFp
(
kCachedPowers_F
[
index
],
kCachedPowers_E
[
index
]);
}
...
...
@@ -238,10 +242,11 @@ inline DiyFp GetCachedPower(int e, int* K) {
}
inline
DiyFp
GetCachedPower10
(
int
exp
,
int
*
outExp
)
{
unsigned
index
=
(
static_cast
<
unsigned
>
(
exp
)
+
348u
)
/
8u
;
*
outExp
=
-
348
+
static_cast
<
int
>
(
index
)
*
8
;
return
GetCachedPowerByIndex
(
index
);
}
RAPIDJSON_ASSERT
(
exp
>=
-
348
);
unsigned
index
=
static_cast
<
unsigned
>
(
exp
+
348
)
/
8u
;
*
outExp
=
-
348
+
static_cast
<
int
>
(
index
)
*
8
;
return
GetCachedPowerByIndex
(
index
);
}
#ifdef __GNUC__
RAPIDJSON_DIAG_POP
...
...
include/rapidjson/internal/strtod.h
View file @
29b6c9b7
...
...
@@ -233,12 +233,14 @@ inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t
while
(
*
decimals
==
'0'
&&
length
>
1
)
{
length
--
;
decimals
++
;
RAPIDJSON_ASSERT
(
decimalPosition
>
0
);
decimalPosition
--
;
}
// Trim trailing zeros
while
(
decimals
[
length
-
1
]
==
'0'
&&
length
>
1
)
{
length
--
;
RAPIDJSON_ASSERT
(
decimalPosition
>
0
);
decimalPosition
--
;
exp
++
;
}
...
...
@@ -248,6 +250,7 @@ inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t
if
(
static_cast
<
int
>
(
length
)
>
kMaxDecimalDigit
)
{
int
delta
=
(
static_cast
<
int
>
(
length
)
-
kMaxDecimalDigit
);
exp
+=
delta
;
RAPIDJSON_ASSERT
(
decimalPosition
>
static_cast
<
unsigned
>
(
delta
));
decimalPosition
-=
static_cast
<
unsigned
>
(
delta
);
length
=
kMaxDecimalDigit
;
}
...
...
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