Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json-c 0.12: Fixed Infinity bug #372

Merged
merged 3 commits into from Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions json_tokener.c
Expand Up @@ -337,6 +337,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
state = json_tokener_state_number;
printbuf_reset(tok->pb);
tok->is_double = 0;
tok->st_pos = 0;
goto redo_char;
default:
tok->err = json_tokener_error_parse_unexpected;
Expand Down
6 changes: 3 additions & 3 deletions tests/testReplaceExisting.c
Expand Up @@ -24,7 +24,7 @@ int main(int argc, char **argv)
int orig_count = 0;
json_object_object_foreach(my_object, key0, val0)
{
printf("Key at index %d is [%s]", orig_count, key0);
printf("Key at index %d is [%s] %d", orig_count, key0, (val0 == NULL));
if (strcmp(key0, "deleteme") == 0)
{
json_object_object_del(my_object, key0);
Expand All @@ -41,7 +41,7 @@ int main(int argc, char **argv)
orig_count = 0;
json_object_object_foreach(my_object, key, val)
{
printf("Key at index %d is [%s]\n", orig_count, key);
printf("Key at index %d is [%s] %d\n", orig_count, key, (val == NULL));
orig_count++;
if (strcmp(key, "foo2") != 0)
continue;
Expand All @@ -56,7 +56,7 @@ int main(int argc, char **argv)
int retval = 0;
json_object_object_foreach(my_object, key2, val2)
{
printf("Key at index %d is [%s]\n", new_count, key2);
printf("Key at index %d is [%s] %d\n", new_count, key2, (val2 == NULL));
new_count++;
if (strcmp(key2, "foo2") != 0)
continue;
Expand Down
20 changes: 10 additions & 10 deletions tests/testReplaceExisting.expected
@@ -1,15 +1,15 @@
==== delete-in-loop test starting ====
Key at index 0 is [foo1] (kept)
Key at index 1 is [foo2] (kept)
Key at index 2 is [deleteme] (deleted)
Key at index 3 is [foo3] (kept)
Key at index 0 is [foo1] 0 (kept)
Key at index 1 is [foo2] 0 (kept)
Key at index 2 is [deleteme] 0 (deleted)
Key at index 3 is [foo3] 0 (kept)
==== replace-value first loop starting ====
Key at index 0 is [foo1]
Key at index 1 is [foo2]
Key at index 0 is [foo1] 0
Key at index 1 is [foo2] 0
replacing value for key [foo2]
Key at index 2 is [foo3]
Key at index 2 is [foo3] 0
==== second loop starting ====
Key at index 0 is [foo1]
Key at index 1 is [foo2]
Key at index 0 is [foo1] 0
Key at index 1 is [foo2] 0
pointer for key [foo2] does match
Key at index 2 is [foo3]
Key at index 2 is [foo3] 0
2 changes: 1 addition & 1 deletion tests/test_parse.c
Expand Up @@ -131,7 +131,7 @@ static void test_basic_parse()
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
json_object_put(new_obj);

new_obj = json_tokener_parse("{ \"abc\": 12, \"foo\": \"bar\", \"bool0\": false, \"bool1\": true, \"arr\": [ 1, 2, 3, null, 5 ] }");
new_obj = json_tokener_parse("{ \"abc\": 12, \"foo\": \"bar\", \"bool0\": false, \"bool1\": true, \"arr\": [ 1, 2, 3, null, 5 ], \"inf\": Infinity, \"-inf\": -Infinity, \"nan\": NaN, \"def\" : -0.22, \"hij\": 0.31 }");
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
json_object_put(new_obj);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_parse.expected
Expand Up @@ -24,7 +24,7 @@ new_obj.to_string()={ }
new_obj.to_string()={ "foo": "bar" }
new_obj.to_string()={ "foo": "bar", "baz": null, "bool0": true }
new_obj.to_string()={ "foo": [ null, "foo" ] }
new_obj.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true, "arr": [ 1, 2, 3, null, 5 ] }
new_obj.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true, "arr": [ 1, 2, 3, null, 5 ], "inf": Infinity, "-inf": -Infinity, "nan": NaN, "def": -0.22, "hij": 0.31 }
==================================
json_tokener_parse_versbose() OK
==================================
Expand Down