Skip to content

Commit bc5dbc6

Browse files
hiharincdunn2001
authored andcommitted
Patch for bug open-source-parsers#53 on version 0.5.0
This is a patch that we have utilized at IDEXX Labs for the the bug described above. We have tested and verified this on x86 32 and 64 bit linux and 32 bit arm.
1 parent 1ac2295 commit bc5dbc6

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/lib_json/json_writer.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <string.h>
1414
#include <sstream>
1515
#include <iomanip>
16+
#include <math.h>
1617

1718
#if defined(_MSC_VER) && _MSC_VER >= 1400 // VC++ 8.0
1819
// Disable warning about strdup being deprecated.
@@ -79,7 +80,29 @@ std::string valueToString(double value) {
7980
sprintf_s(buffer, sizeof(buffer), "%.16g", value);
8081
#endif
8182
#else
82-
snprintf(buffer, sizeof(buffer), "%.16g", value);
83+
if ( isfinite( value ))
84+
{
85+
snprintf(buffer, sizeof(buffer), "%.16g", value);
86+
}
87+
else
88+
{
89+
// IEEE standard states that NaN values will not compare to themselves
90+
if ( value != value)
91+
{
92+
snprintf(buffer, sizeof(buffer), "null");
93+
}
94+
else if ( value < 0)
95+
{
96+
snprintf(buffer, sizeof(buffer), "-1e+9999");
97+
}
98+
else
99+
{
100+
snprintf(buffer, sizeof(buffer), "1e+9999");
101+
}
102+
// nothing more to do, return.
103+
return buffer;
104+
}
105+
83106
#endif
84107
fixNumericLocale(buffer, buffer + strlen(buffer));
85108
return buffer;

0 commit comments

Comments
 (0)