| 398 | } |
| 399 | |
| 400 | CJSON_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 | |
| 427 | typedef struct |
| 428 | { |
nothing calls this directly
no test coverage detected