-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
Don't use a nonliteral format string in test/fheap.c:begin_test(). #1401
Conversation
Use snprintf. Don't duplicate a string on the heap unnecessarily.
HDassert(del_str); | ||
test_desc = (char *)H5MM_malloc(HDstrlen(del_str) + HDstrlen(base_desc)); | ||
HDsprintf(test_desc, base_desc, del_str); | ||
size_t test_desc_len = strlen(base_desc) + sizeof(" ") + strlen(del_str); |
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.
Think this might need an extra +1 for the NUL terminator.
/* Remove half of total objects from heap */ | ||
if (tparam->del_dir == FHEAP_DEL_FORWARD) | ||
if (tparam->drain_half == FHEAP_DEL_DRAIN_ALL) | ||
str = H5MM_strdup("(all - forward)"); | ||
return "(all - forward)"; |
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.
I'm all for removing memory allocations where they aren't really needed!
On Fri, Jan 28, 2022 at 02:47:17PM -0800, jhendersonHDF wrote:
@jhendersonHDF commented on this pull request.
>
/*
* Test filling & removing all (small) objects from root direct block of absolute heap
*/
- del_str = get_del_string(tparam);
- HDassert(del_str);
- test_desc = (char *)H5MM_malloc(HDstrlen(del_str) + HDstrlen(base_desc));
- HDsprintf(test_desc, base_desc, del_str);
+ size_t test_desc_len = strlen(base_desc) + sizeof(" ") + strlen(del_str);
Think this might need an extra +1 for the NUL terminator.
sizeof(" ") includes the NUL terminator of " ".
Dave
|
Ah that's true. I mistakenly read as strlen(" "). |
No description provided.