From 629c354390b5ed1984a37b87fea6cf47946fc83c Mon Sep 17 00:00:00 2001 From: rmallins Date: Wed, 6 Sep 2017 23:50:38 +0100 Subject: [PATCH] Rewrite test for cJSON_ParseWithOpts() to expect non-null error pointer in error case and change code to match new expectations. --- cJSON.c | 6 ++---- cJSON.h | 2 +- tests/parse_with_opts.c | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/cJSON.c b/cJSON.c index 42481ed..1d1feea 100644 --- a/cJSON.c +++ b/cJSON.c @@ -1006,10 +1006,8 @@ fail: { *return_parse_end = (const char*)local_error.json + local_error.position; } - else - { - global_error = local_error; - } + + global_error = local_error; } return NULL; diff --git a/cJSON.h b/cJSON.h index 3a08b3a..0be19b1 100644 --- a/cJSON.h +++ b/cJSON.h @@ -139,7 +139,7 @@ CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks); /* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ -/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error. If not, then cJSON_GetErrorPtr() does the job. */ +/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */ CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); /* Render a cJSON entity to text for transfer/storage. */ diff --git a/tests/parse_with_opts.c b/tests/parse_with_opts.c index e75a69a..37a52e9 100644 --- a/tests/parse_with_opts.c +++ b/tests/parse_with_opts.c @@ -46,7 +46,7 @@ static void parse_with_opts_should_handle_empty_strings(void) TEST_ASSERT_NULL(cJSON_ParseWithOpts(empty_string, &error_pointer, false)); TEST_ASSERT_EQUAL_PTR(empty_string, error_pointer); - TEST_ASSERT_EQUAL_PTR(NULL, cJSON_GetErrorPtr()); + TEST_ASSERT_EQUAL_PTR(empty_string, cJSON_GetErrorPtr()); } static void parse_with_opts_should_handle_incomplete_json(void) @@ -56,7 +56,7 @@ static void parse_with_opts_should_handle_incomplete_json(void) TEST_ASSERT_NULL(cJSON_ParseWithOpts(json, &parse_end, false)); TEST_ASSERT_EQUAL_PTR(json + strlen(json), parse_end); - TEST_ASSERT_NULL(cJSON_GetErrorPtr()); + TEST_ASSERT_EQUAL_PTR(json + strlen(json), cJSON_GetErrorPtr()); } static void parse_with_opts_should_require_null_if_requested(void)