MCPcopy Create free account
hub / github.com/Tencent/Hardcoder / cJSON_strdup

Function cJSON_strdup

libapp2sys/src/main/cpp/cjson/cJSON.c:150–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc };
149
150static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks)
151{
152 size_t length = 0;
153 unsigned char *copy = NULL;
154
155 if (string == NULL)
156 {
157 return NULL;
158 }
159
160 length = strlen((const char*)string) + sizeof("");
161 copy = (unsigned char*)hooks->allocate(length);
162 if (copy == NULL)
163 {
164 return NULL;
165 }
166 memcpy(copy, string, length);
167
168 return copy;
169}
170
171CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks)
172{

Callers 5

add_item_to_objectFunction · 0.85
replace_item_in_objectFunction · 0.85
cJSON_CreateStringFunction · 0.85
cJSON_CreateRawFunction · 0.85
cJSON_DuplicateFunction · 0.85

Calls 1

allocateMethod · 0.80

Tested by

no test coverage detected