From bc5dbc6d41279b22fe9a4a0664ab2f9f090744ae Mon Sep 17 00:00:00 2001 From: David West Date: Thu, 31 Jul 2014 13:18:02 -0400 Subject: [PATCH] Patch for bug #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. --- src/lib_json/json_writer.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 46f32e1..77ed27d 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #if defined(_MSC_VER) && _MSC_VER >= 1400 // VC++ 8.0 // Disable warning about strdup being deprecated. @@ -79,7 +80,29 @@ std::string valueToString(double value) { sprintf_s(buffer, sizeof(buffer), "%.16g", value); #endif #else - snprintf(buffer, sizeof(buffer), "%.16g", value); + if ( isfinite( value )) + { + snprintf(buffer, sizeof(buffer), "%.16g", value); + } + else + { + // IEEE standard states that NaN values will not compare to themselves + if ( value != value) + { + snprintf(buffer, sizeof(buffer), "null"); + } + else if ( value < 0) + { + snprintf(buffer, sizeof(buffer), "-1e+9999"); + } + else + { + snprintf(buffer, sizeof(buffer), "1e+9999"); + } + // nothing more to do, return. + return buffer; + } + #endif fixNumericLocale(buffer, buffer + strlen(buffer)); return buffer;