Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b45f48e

Browse files
fix: add allocate check for replace_item_in_object (DaveGamble#675)
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
1 parent a6424b8 commit b45f48e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

‎cJSON.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,19 @@ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void)
9696
return (const char*) (global_error.json + global_error.position);
9797
}
9898

99-
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item)
99+
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item)
100100
{
101-
if (!cJSON_IsString(item))
101+
if (!cJSON_IsString(item))
102102
{
103103
return NULL;
104104
}
105105

106106
return item->valuestring;
107107
}
108108

109-
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item)
109+
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item)
110110
{
111-
if (!cJSON_IsNumber(item))
111+
if (!cJSON_IsNumber(item))
112112
{
113113
return (double) NAN;
114114
}
@@ -511,7 +511,7 @@ static unsigned char* ensure(printbuffer * const p, size_t needed)
511511

512512
return NULL;
513513
}
514-
514+
515515
memcpy(newbuffer, p->buffer, p->offset + 1);
516516
p->hooks.deallocate(p->buffer);
517517
}
@@ -1107,7 +1107,7 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer
11071107
}
11081108

11091109
buffer.content = (const unsigned char*)value;
1110-
buffer.length = buffer_length;
1110+
buffer.length = buffer_length;
11111111
buffer.offset = 0;
11121112
buffer.hooks = global_hooks;
11131113

@@ -2361,6 +2361,11 @@ static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSO
23612361
cJSON_free(replacement->string);
23622362
}
23632363
replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks);
2364+
if (replacement->string == NULL)
2365+
{
2366+
return false;
2367+
}
2368+
23642369
replacement->type &= ~cJSON_StringIsConst;
23652370

23662371
return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement);
@@ -2693,7 +2698,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int co
26932698
if (a && a->child) {
26942699
a->child->prev = n;
26952700
}
2696-
2701+
26972702
return a;
26982703
}
26992704

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /