Skip to content
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

Correct the error in the comment for unsafe_yyjson_mut_strncpy #159

Merged
merged 1 commit into from
Feb 27, 2024

Conversation

hxdnshx
Copy link
Contributor

@hxdnshx hxdnshx commented Feb 27, 2024

Similar to yyjson_mut_obj_add_strcpy, in fact, the val & len in yyjson_mut_obj_add_strncpy have already been assigned values
and do not need to have their lifetimes guaranteed.

yyjson/src/yyjson.h

Lines 6963 to 6974 in 0eca326

yyjson_api_inline bool yyjson_mut_obj_add_strncpy(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
const char *_key,
const char *_val,
size_t _len) {
if (yyjson_unlikely(!_val)) return false;
yyjson_mut_obj_add_func({
val->uni.str = unsafe_yyjson_mut_strncpy(doc, _val, _len);
if (yyjson_unlikely(!val->uni.str)) return false;
val->tag = ((uint64_t)_len << YYJSON_TAG_BIT) | YYJSON_TYPE_STR;
});
}

The call to unsafe_yyjson_mut_strncpy in the above code also proves this point.

@ibireme
Copy link
Owner

ibireme commented Feb 27, 2024

Thanks.

@ibireme ibireme merged commit 2ca3753 into ibireme:master Feb 27, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants