| 409 | } |
| 410 | |
| 411 | CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring) |
| 412 | { |
| 413 | char *copy = NULL; |
| 414 | /* if object's type is not cJSON_String or is cJSON_IsReference, it should not set valuestring */ |
| 415 | if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference)) |
| 416 | { |
| 417 | return NULL; |
| 418 | } |
| 419 | if (strlen(valuestring) <= strlen(object->valuestring)) |
| 420 | { |
| 421 | strcpy(object->valuestring, valuestring); |
| 422 | return object->valuestring; |
| 423 | } |
| 424 | copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks); |
| 425 | if (copy == NULL) |
| 426 | { |
| 427 | return NULL; |
| 428 | } |
| 429 | if (object->valuestring != NULL) |
| 430 | { |
| 431 | cJSON_free(object->valuestring); |
| 432 | } |
| 433 | object->valuestring = copy; |
| 434 | |
| 435 | return copy; |
| 436 | } |
| 437 | |
| 438 | typedef struct |
| 439 | { |
nothing calls this directly
no test coverage detected
searching dependent graphs…