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
8fbe4429
Commit
8fbe4429
authored
Jan 20, 2016
by
Milo Yip
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #510 from miloyip/issue509_writingnaninf
Fix #509 by checking Nan/Inf when writing a double
parents
78c7d54a
bab80e7c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
1 deletion
+33
-1
ieee754.h
include/rapidjson/internal/ieee754.h
+1
-0
writer.h
include/rapidjson/writer.h
+7
-1
writertest.cpp
test/unittest/writertest.cpp
+25
-0
No files found.
include/rapidjson/internal/ieee754.h
View file @
8fbe4429
...
...
@@ -40,6 +40,7 @@ public:
bool
IsNan
()
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
IsZero
()
const
{
return
(
u_
&
(
kExponentMask
|
kSignificandMask
))
==
0
;
}
...
...
include/rapidjson/writer.h
View file @
8fbe4429
...
...
@@ -139,7 +139,7 @@ public:
}
bool
Key
(
const
Ch
*
str
,
SizeType
length
,
bool
copy
=
false
)
{
return
String
(
str
,
length
,
copy
);
}
bool
EndObject
(
SizeType
memberCount
=
0
)
{
(
void
)
memberCount
;
RAPIDJSON_ASSERT
(
level_stack_
.
GetSize
()
>=
sizeof
(
Level
));
...
...
@@ -235,6 +235,9 @@ protected:
}
bool
WriteDouble
(
double
d
)
{
if
(
internal
::
Double
(
d
).
IsNanOrInf
())
return
false
;
char
buffer
[
25
];
char
*
end
=
internal
::
dtoa
(
d
,
buffer
);
for
(
char
*
p
=
buffer
;
p
!=
end
;
++
p
)
...
...
@@ -381,6 +384,9 @@ inline bool Writer<StringBuffer>::WriteUint64(uint64_t u) {
template
<>
inline
bool
Writer
<
StringBuffer
>::
WriteDouble
(
double
d
)
{
if
(
internal
::
Double
(
d
).
IsNanOrInf
())
return
false
;
char
*
buffer
=
os_
->
Push
(
25
);
char
*
end
=
internal
::
dtoa
(
d
,
buffer
);
os_
->
Pop
(
static_cast
<
size_t
>
(
25
-
(
end
-
buffer
)));
...
...
test/unittest/writertest.cpp
View file @
8fbe4429
...
...
@@ -375,3 +375,28 @@ TEST(Writer, InvalidEventSequence) {
EXPECT_FALSE
(
writer
.
IsComplete
());
}
}
extern
double
zero
;
// clang -Wmissing-variable-declarations
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