open-source-parsers/jsoncpp — pull request #21 by hiharin (2014-07-31 17:21:58+00:00)
Title: 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.

also a c++ program to verify the fix:
#include "json/value.h"
#include "json/reader.h"
#include "json/writer.h"
#include
#include
#include
#include
#include
using namespace std;
const char* FILENAME = "test.json";

int main()
{
Json::Value root;
Json::Value data;

data["myval1"] = 0.0/0.0;
data["myval2"] = 0.1/0.0;
data["myval3"] = -0.1/0.0;
root["TEST_INF_NAN"] = data;

ofstream outstream(FILENAME, ofstream::binary );
outstream.write(root.toStyledString().c_str(), root.toStyledString().size());
outstream.close();
Json::StyledWriter writer;

Json::Value valueFromFile;
Json::Reader reader;

ifstream instream( FILENAME , ifstream::binary );
if (!reader.parse( instream, valueFromFile, false ))
{
printf("FAIL.\n");
return 1;
}

Json::Value child = valueFromFile.get( "TEST_INF_NAN", Json::Value() );

if ( !child["myval1"].isNull() )
{
printf("FAIL.\n");
return 1;
}

if ( !child["myval2"].asDouble() == std::numeric_limits::infinity() )
{
printf("FAIL.\n");
return 1;
}

if ( !child["myval3"].asDouble() == ( std::numeric_limits::infinity() * -1 ) )
{
printf("FAIL.\n");
return 1;
}

char buff[24];
sprintf(buff, "rm %s", FILENAME);
system(buff);
printf("PASS.\n");
return 0;
}