]> git.cworth.org Git - apitrace/commitdiff
Avoid inserting 'inf' and friends into the json output.
authorCarl Worth <cworth@cworth.org>
Mon, 30 Jul 2012 22:01:15 +0000 (15:01 -0700)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 2 Aug 2012 17:26:31 +0000 (18:26 +0100)
The JSON-generating code was previously carefult to avoid emitting NaN
into its output, but it would still write "inf" for an infinite value,
(which is invalid JSON).

Fix by calling writeNull for any value for which std::isfinite returns
false, (rather than the previous test for merely (n != n)).

retrace/json.hpp

index 6af1f4c6c4fab898fae8ca730c5092cefc850459..2f50a8c55aedc28fccad91c1493031289113cc2b 100644 (file)
 #include <stddef.h>
 #include <wchar.h>
 
+#ifdef _MSC_VER
+#  include <float.h>
+#  define isfinite _finite
+#else
+#  include <math.h> // isfinite
+#endif
+
 #include <iomanip>
 #include <limits>
 #include <ostream>
@@ -328,8 +335,8 @@ public:
 
     template<class T>
     inline void writeNumber(T n) {
-        if (n != n) {
-            // NaN
+        if (!isfinite(n)) {
+            // NaN/Inf
             writeNull();
         } else {
             separator();