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
ad1d22eb
Commit
ad1d22eb
authored
Jan 19, 2016
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #509 by checking Nan/Inf when writing a double
parent
44f81f09
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
0 deletions
+31
-0
ieee754.h
include/rapidjson/internal/ieee754.h
+1
-0
writer.h
include/rapidjson/writer.h
+6
-0
writertest.cpp
test/unittest/writertest.cpp
+24
-0
No files found.
include/rapidjson/internal/ieee754.h
View file @
ad1d22eb
...
@@ -40,6 +40,7 @@ public:
...
@@ -40,6 +40,7 @@ public:
bool
IsNan
()
const
{
return
(
u_
&
kExponentMask
)
==
kExponentMask
&&
Significand
()
!=
0
;
}
bool
IsNan
()
const
{
return
(
u_
&
kExponentMask
)
==
kExponentMask
&&
Significand
()
!=
0
;
}
bool
IsInf
()
const
{
return
(
u_
&
kExponentMask
)
==
kExponentMask
&&
Significand
()
==
0
;
}
bool
IsInf
()
const
{
return
(
u_
&
kExponentMask
)
==
kExponentMask
&&
Significand
()
==
0
;
}
bool
IsNanOrInf
()
const
{
return
(
u_
&
kExponentMask
)
==
kExponentMask
;
}
bool
IsNormal
()
const
{
return
(
u_
&
kExponentMask
)
!=
0
||
Significand
()
==
0
;
}
bool
IsNormal
()
const
{
return
(
u_
&
kExponentMask
)
!=
0
||
Significand
()
==
0
;
}
bool
IsZero
()
const
{
return
(
u_
&
(
kExponentMask
|
kSignificandMask
))
==
0
;
}
bool
IsZero
()
const
{
return
(
u_
&
(
kExponentMask
|
kSignificandMask
))
==
0
;
}
...
...
include/rapidjson/writer.h
View file @
ad1d22eb
...
@@ -235,6 +235,9 @@ protected:
...
@@ -235,6 +235,9 @@ protected:
}
}
bool
WriteDouble
(
double
d
)
{
bool
WriteDouble
(
double
d
)
{
if
(
internal
::
Double
(
d
).
IsNanOrInf
())
return
false
;
char
buffer
[
25
];
char
buffer
[
25
];
char
*
end
=
internal
::
dtoa
(
d
,
buffer
);
char
*
end
=
internal
::
dtoa
(
d
,
buffer
);
for
(
char
*
p
=
buffer
;
p
!=
end
;
++
p
)
for
(
char
*
p
=
buffer
;
p
!=
end
;
++
p
)
...
@@ -381,6 +384,9 @@ inline bool Writer<StringBuffer>::WriteUint64(uint64_t u) {
...
@@ -381,6 +384,9 @@ inline bool Writer<StringBuffer>::WriteUint64(uint64_t u) {
template
<>
template
<>
inline
bool
Writer
<
StringBuffer
>::
WriteDouble
(
double
d
)
{
inline
bool
Writer
<
StringBuffer
>::
WriteDouble
(
double
d
)
{
if
(
internal
::
Double
(
d
).
IsNanOrInf
())
return
false
;
char
*
buffer
=
os_
->
Push
(
25
);
char
*
buffer
=
os_
->
Push
(
25
);
char
*
end
=
internal
::
dtoa
(
d
,
buffer
);
char
*
end
=
internal
::
dtoa
(
d
,
buffer
);
os_
->
Pop
(
static_cast
<
size_t
>
(
25
-
(
end
-
buffer
)));
os_
->
Pop
(
static_cast
<
size_t
>
(
25
-
(
end
-
buffer
)));
...
...
test/unittest/writertest.cpp
View file @
ad1d22eb
...
@@ -375,3 +375,27 @@ TEST(Writer, InvalidEventSequence) {
...
@@ -375,3 +375,27 @@ TEST(Writer, InvalidEventSequence) {
EXPECT_FALSE
(
writer
.
IsComplete
());
EXPECT_FALSE
(
writer
.
IsComplete
());
}
}
}
}
double
zero
=
0.0
;
// Use global variable to prevent compiler warning
TEST
(
Writer
,
NaN
)
{
double
nan
=
zero
/
zero
;
EXPECT_TRUE
(
internal
::
Double
(
nan
).
IsNan
());
StringBuffer
buffer
;
Writer
<
StringBuffer
>
writer
(
buffer
);
EXPECT_FALSE
(
writer
.
Double
(
nan
));
}
TEST
(
Writer
,
Inf
)
{
double
inf
=
1.0
/
zero
;
EXPECT_TRUE
(
internal
::
Double
(
inf
).
IsInf
());
StringBuffer
buffer
;
{
Writer
<
StringBuffer
>
writer
(
buffer
);
EXPECT_FALSE
(
writer
.
Double
(
inf
));
}
{
Writer
<
StringBuffer
>
writer
(
buffer
);
EXPECT_FALSE
(
writer
.
Double
(
-
inf
));
}
}
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