MCPcopy Index your code
hub / github.com/antirez/botlib / cJSON_SetValuestring

Function cJSON_SetValuestring

cJSON.c:400–425  ·  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->type & cJSON_String) || (object->type & cJSON_IsReference))
405 {
406 return NULL;
407 }
408 if (strlen(valuestring) <= strlen(object->valuestring))
409 {
410 strcpy(object->valuestring, valuestring);
411 return object->valuestring;
412 }
413 copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks);
414 if (copy == NULL)
415 {
416 return NULL;
417 }
418 if (object->valuestring != NULL)
419 {
420 cJSON_free(object->valuestring);
421 }
422 object->valuestring = copy;
423
424 return copy;
425}
426
427typedef struct
428{

Callers

nothing calls this directly

Calls 2

cJSON_strdupFunction · 0.85
cJSON_freeFunction · 0.85

Tested by

no test coverage detected