MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / cJSON_SetValuestring

Function cJSON_SetValuestring

TheForceEngine/TFE_System/cJSON.c:400–430  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

cJSON_strdupFunction · 0.85
cJSON_freeFunction · 0.85

Tested by

no test coverage detected