Invalid read when querying for a field that doesn't exist
Created by: shreyasbharath
Hi again,
I was writing some simple parsing tests and came across this error when I ran my test on Valgrind.
Given a test vector like this one -
static const char *jsonSimpleObject = R"*(
{
"firstname": "first",
"lastname": "last"
}
)*";
If I try to get a field that doesn't exist like so -
char *json = strclone( jsonSimpleObject );
JsonHashTable hashTable = parser.parseHashTable( json );
EXPECT_TRUE( hashTable.success() );
EXPECT_THAT( hashTable.getString( "firstname" ), StrEq( "first" ) );
EXPECT_THAT( hashTable.getString( "lastname" ), StrEq( "last" ) );
EXPECT_THAT( hashTable.getString( "middlename" ), Eq( nullptr ) );
The error reported by Valgrind is as below -
==16231== Conditional jump or move depends on uninitialised value(s)
==16231== at 0x81983E5: JsonObjectBase::getNestedTokenCount(jsmntok_t*) (JsonObjectBase.cpp:18)
==16231== by 0x8198253: JsonHashTable::getToken(char const*) (JsonHashTable.cpp:44)
==16231== by 0x81983A5: JsonHashTable::getString(char const*) (JsonHashTable.cpp:83)
==16231== by 0x80EF597: