Note: when passing a NULL valuestring, cJSON_SetValuestring treats this as an error and return NULL */
| 401 | |
| 402 | /* Note: when passing a NULL valuestring, cJSON_SetValuestring treats this as an error and return NULL */ |
| 403 | CJSON_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 | |
| 435 | typedef struct |
| 436 | { |
nothing calls this directly
no test coverage detected