Better argument validation
All pointer arguments are now tested for NULL. json_string() now also tests that strdup() succeeds. This is to ensure that no NULL values end up in data structures. Also desribe the different sources of errors in documentation.
This commit is contained in:
@@ -27,6 +27,9 @@ int main()
|
||||
if(json_array_size(array) != 0)
|
||||
fail("empty array has nonzero size");
|
||||
|
||||
if(!json_array_append(array, NULL))
|
||||
fail("able to append NULL");
|
||||
|
||||
if(json_array_append(array, five))
|
||||
fail("unable to append");
|
||||
|
||||
@@ -54,6 +57,9 @@ int main()
|
||||
if(json_array_set(array, 0, seven))
|
||||
fail("unable to set value");
|
||||
|
||||
if(!json_array_set(array, 0, NULL))
|
||||
fail("able to set NULL");
|
||||
|
||||
if(json_array_size(array) != 2)
|
||||
fail("wrong array size");
|
||||
|
||||
@@ -85,16 +91,26 @@ int main()
|
||||
fail("got wrong value");
|
||||
}
|
||||
|
||||
json_array_set_new(array, 15, json_integer(123));
|
||||
if(json_array_set_new(array, 15, json_integer(123)))
|
||||
fail("unable to set new value");
|
||||
|
||||
value = json_array_get(array, 15);
|
||||
if(!json_is_integer(value) || json_integer_value(value) != 123)
|
||||
fail("json_array_set_new works incorrectly");
|
||||
|
||||
json_array_append_new(array, json_integer(321));
|
||||
if(!json_array_set_new(array, 15, NULL))
|
||||
fail("able to set_new NULL value");
|
||||
|
||||
if(json_array_append_new(array, json_integer(321)))
|
||||
fail("unable to append new value");
|
||||
|
||||
value = json_array_get(array, json_array_size(array) - 1);
|
||||
if(!json_is_integer(value) || json_integer_value(value) != 321)
|
||||
fail("json_array_append_new works incorrectly");
|
||||
|
||||
if(!json_array_append_new(array, NULL))
|
||||
fail("able to append_new NULL value");
|
||||
|
||||
json_decref(five);
|
||||
json_decref(seven);
|
||||
json_decref(array);
|
||||
|
||||
@@ -29,6 +29,12 @@ int main()
|
||||
if(json_object_set(object, "a", string))
|
||||
fail("unable to set value");
|
||||
|
||||
if(!json_object_set(object, NULL, string))
|
||||
fail("able to set NULL key");
|
||||
|
||||
if(!json_object_set(object, "a", NULL))
|
||||
fail("able to set NULL value");
|
||||
|
||||
iter = json_object_iter(object);
|
||||
if(!iter)
|
||||
fail("unable to get iterator");
|
||||
@@ -105,11 +111,19 @@ int main()
|
||||
fail("unable to set value");
|
||||
|
||||
|
||||
json_object_set_new(object, "foo", json_integer(123));
|
||||
if(json_object_set_new(object, "foo", json_integer(123)))
|
||||
fail("unable to set new value");
|
||||
|
||||
value = json_object_get(object, "foo");
|
||||
if(!json_is_integer(value) || json_integer_value(value) != 123)
|
||||
fail("json_object_set_new works incorrectly");
|
||||
|
||||
if(!json_object_set_new(object, NULL, json_integer(432)))
|
||||
fail("able to set_new NULL key");
|
||||
|
||||
if(!json_object_set_new(object, "foo", NULL))
|
||||
fail("able to set_new NULL value");
|
||||
|
||||
json_decref(string);
|
||||
json_decref(other_string);
|
||||
json_decref(object);
|
||||
|
||||
@@ -58,6 +58,10 @@ int main()
|
||||
fail("invalid string value");
|
||||
json_decref(value);
|
||||
|
||||
value = json_string(NULL);
|
||||
if(value)
|
||||
fail("json_string(NULL) failed");
|
||||
|
||||
value = json_integer(123);
|
||||
if(!value)
|
||||
fail("json_integer failed");
|
||||
|
||||
Reference in New Issue
Block a user