Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_bu
/* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number)
{
if (object == NULL)
{
return (double)NAN;
}

if (number >= INT_MAX)
{
object->valueint = INT_MAX;
Expand Down
5 changes: 3 additions & 2 deletions tests/misc_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "unity/examples/unity_config.h"
#include "unity/src/unity.h"
Expand Down Expand Up @@ -478,8 +479,8 @@ static void cjson_functions_should_not_crash_with_null_pointers(void)
TEST_ASSERT_NULL(cJSON_SetValuestring(corruptedString, "test"));
TEST_ASSERT_NULL(cJSON_SetValuestring(item, NULL));
cJSON_Minify(NULL);
/* skipped because it is only used via a macro that checks for NULL */
/* cJSON_SetNumberHelper(NULL, 0); */
/* cJSON_SetNumberHelper should handle NULL gracefully */
TEST_ASSERT_TRUE(isnan(cJSON_SetNumberHelper(NULL, 0)));

/* restore corrupted item2 to delete it */
item2->prev = originalPrev;
Expand Down