| 394 | } |
| 395 | |
| 396 | CJSON_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 | |
| 423 | typedef struct |
| 424 | { |
nothing calls this directly
no test coverage detected