MCPcopy Create free account
hub / github.com/OpenIPC/firmware / cJSON_SetValuestring

Function cJSON_SetValuestring

general/package/xmdp/src/cjson/cJSON.c:396–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

394}
395
396CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
397{
398 char *copy = NULL;
399 /* if object's type is not cJSON_String or is cJSON_IsReference, it should not set valuestring */
400 if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference))
401 {
402 return NULL;
403 }
404 if (strlen(valuestring) <= strlen(object->valuestring))
405 {
406 strcpy(object->valuestring, valuestring);
407 return object->valuestring;
408 }
409 copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks);
410 if (copy == NULL)
411 {
412 return NULL;
413 }
414 if (object->valuestring != NULL)
415 {
416 cJSON_free(object->valuestring);
417 }
418 object->valuestring = copy;
419
420 return copy;
421}
422
423typedef struct
424{

Callers

nothing calls this directly

Calls 2

cJSON_strdupFunction · 0.85
cJSON_freeFunction · 0.85

Tested by

no test coverage detected