-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add new function of cJSON_SetValuestring
#451
Conversation
cJSON.c
Outdated
return NULL; | ||
} | ||
memcpy(copy, valuestring, length); | ||
if (!(object->type & cJSON_IsReference) && (object->valuestring != NULL)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repeated check in a single thread
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks your reminder!
cJSON.c
Outdated
{ | ||
return NULL; | ||
} | ||
length = strlen(valuestring) + sizeof(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the new str length does not exceed the current value, whether to re-allocate memory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good suggestion, In this case, we don't need to allocate memory, just re-assign the valuestring
f7bd395
to
b9eb61c
Compare
cJSON_SetValuestringToObject
cJSON_SetValuestring
Changes
valuestring
, we have to free the old value carefully, to make sure people could easily change it,cJSON_SetValuestring
has been added.