Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@ typedef struct {
size_t position;
} error;
static error global_error = { NULL, 0 };

CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void)
{
return (const char*) (global_error.json + global_error.position);
if (global_error.json == NULL)
{
return NULL;
}

return (const char *)(global_error.json + global_error.position);
}

CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item)
Expand Down
9 changes: 8 additions & 1 deletion tests/misc_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,14 @@ static void cjson_parse_big_numbers_should_not_report_error(void)
cJSON_Delete(valid_big_number_json_object1);
cJSON_Delete(valid_big_number_json_object2);
}
static void cjson_get_error_ptr_should_return_null_for_null_input(void)
{
cJSON *json = cJSON_Parse(NULL);
const char *error_ptr = cJSON_GetErrorPtr();

TEST_ASSERT_NULL(json);
TEST_ASSERT_NULL(error_ptr);
}
int CJSON_CDECL main(void)
{
UNITY_BEGIN();
Expand Down Expand Up @@ -833,6 +840,6 @@ int CJSON_CDECL main(void)
RUN_TEST(cjson_set_valuestring_to_object_should_not_leak_memory);
RUN_TEST(cjson_set_bool_value_must_not_break_objects);
RUN_TEST(cjson_parse_big_numbers_should_not_report_error);

RUN_TEST(cjson_get_error_ptr_should_return_null_for_null_input);
return UNITY_END();
}