Skip to content

Conversation

@hiharin
Copy link
Contributor

@hiharin hiharin commented Jul 31, 2014

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 <stdio.h>

include

include <string.h>

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<double>::infinity() )
{
    printf("FAIL.\n");
    return 1;
}

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

char buff[24];
sprintf(buff, "rm %s", FILENAME); 
system(buff);
printf("PASS.\n");
return 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.
@cdunn2001
Copy link
Contributor

Patch for #53 NaN and infinity are handled incorrectly

@cdunn2001 cdunn2001 merged this pull request into open-source-parsers:master Aug 13, 2014
cdunn2001 added a commit that referenced this pull request Aug 13, 2014
Hmmm. Not ideal. A round-trip should reproduce the original, but null -> NaN -> ? But I guess it's no worse than it was.

The different behavior for Win CE is troubling, but it only affects people who are using these extreme values.

I've worked with Inf/NaN before, so I understand your pain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants