MCPcopy Create free account
hub / github.com/Netis/cloud-probe / cJSON_SetValuestring

Function cJSON_SetValuestring

cpworker/src/cJSON/cJSON.c:403–433  ·  view source on GitHub ↗

Note: when passing a NULL valuestring, cJSON_SetValuestring treats this as an error and return NULL */

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

cJSON_strdupFunction · 0.85
cJSON_freeFunction · 0.85

Tested by

no test coverage detected