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

Replace sprintf() with snprintf() to remove Xcode/clang warning. #4001

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions test/filter_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,7 @@ test_creating_groups_using_plugins(hid_t fid)
for (i = 0; i < N_SUBGROUPS; i++) {
char *sp = subgroup_name;

sp += snprintf(subgroup_name, sizeof(subgroup_name), SUBGROUP_PREFIX);
sprintf(sp, "%d", i);
Copy link
Collaborator

@jhendersonHDF jhendersonHDF Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on a quick reading of the code, I think these two calls should just be combined into a single snprintf(subgroup_name, sizeof(subgroup_name), SUBGROUP_PREFIX "%d");
Doesn't seem like sp or the extra call to sprintf is needed here.

sp += snprintf(subgroup_name, sizeof(subgroup_name), SUBGROUP_PREFIX "%d", i);

if ((sub_gid = H5Gcreate2(gid, subgroup_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
TEST_ERROR;
Expand Down Expand Up @@ -908,8 +907,7 @@ test_opening_groups_using_plugins(hid_t fid)
for (i = 0; i < N_SUBGROUPS; i++) {
char *sp = subgroup_name;

sp += snprintf(subgroup_name, sizeof(subgroup_name), SUBGROUP_PREFIX);
sprintf(sp, "%d", i);
sp += snprintf(subgroup_name, sizeof(subgroup_name), SUBGROUP_PREFIX "%d", i);

if ((sub_gid = H5Gopen2(gid, subgroup_name, H5P_DEFAULT)) < 0)
TEST_ERROR;
Expand Down
Loading