Disallow NaN or Inf real values

This commit is contained in:
Petri Lehtinen
2012-09-13 21:30:19 +03:00
parent ee13c667f1
commit 4118315afa
2 changed files with 46 additions and 2 deletions

View File

@@ -5,6 +5,7 @@
* it under the terms of the MIT license. See LICENSE for details.
*/
#include <math.h>
#include <jansson.h>
#include "util.h"
@@ -39,4 +40,34 @@ static void run_tests()
json_decref(integer);
json_decref(real);
#ifdef NAN
real = json_real(NAN);
if(real != NULL)
fail("could construct a real from NaN");
real = json_real(1.0);
if(json_real_set(real, NAN) != -1)
fail("could set a real to NaN");
if(json_real_value(real) != 1.0)
fail("real value changed unexpectedly");
json_decref(real);
#endif
#ifdef INFINITY
real = json_real(INFINITY);
if(real != NULL)
fail("could construct a real from Inf");
real = json_real(1.0);
if(json_real_set(real, INFINITY) != -1)
fail("could set a real to Inf");
if(json_real_value(real) != 1.0)
fail("real value changed unexpectedly");
json_decref(real);
#endif
}