diff options
author | Petri Lehtinen <petri@digip.org> | 2013-04-15 08:42:23 +0300 |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2013-04-15 08:49:09 +0300 |
commit | 867079c820b3d9df472308244810782d0651cf08 (patch) | |
tree | 21c41078adcfc72c538d83d691a7f016370c8030 /test/suites/api | |
parent | bbd3b0ca4ffee0e035eb012350cf4fd3e5e3d587 (diff) | |
download | jansson-867079c820b3d9df472308244810782d0651cf08.zip jansson-867079c820b3d9df472308244810782d0651cf08.tar.gz jansson-867079c820b3d9df472308244810782d0651cf08.tar.bz2 |
json_dump*(): Don't crash if json is NULL and JSON_ENCODE_ANY is set
Diffstat (limited to 'test/suites/api')
-rw-r--r-- | test/suites/api/test_dump.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/suites/api/test_dump.c b/test/suites/api/test_dump.c index 8cd659c..334dbfa 100644 --- a/test/suites/api/test_dump.c +++ b/test/suites/api/test_dump.c @@ -9,6 +9,26 @@ #include <string.h> #include "util.h" +static int encode_null_callback(void *ptr, size_t size, void *data) +{ + return 0; +} + +static void encode_null() +{ + if(json_dumps(NULL, JSON_ENCODE_ANY) != NULL) + fail("json_dumps didn't fail for NULL"); + + if(json_dumpf(NULL, stderr, JSON_ENCODE_ANY) != -1) + fail("json_dumpf didn't fail for NULL"); + + /* Don't test json_dump_file to avoid creating a file */ + + if(json_dump_callback(NULL, encode_null_callback, NULL, JSON_ENCODE_ANY) != -1) + fail("json_dump_callback didn't fail for NULL"); +} + + static void encode_twice() { /* Encode an empty object/array, add an item, encode again */ @@ -159,6 +179,7 @@ static void escape_slashes() static void run_tests() { + encode_null(); encode_twice(); circular_references(); encode_other_than_array_or_object(); |