From c064d3481b582653c1e0d0043a17527fd73e8c4d Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Wed, 22 Jun 2022 14:58:18 -0400 Subject: sprintf to snprintf (#1815) * Straightforward conversion of sprintf to the safer snprintf * Trickier conversion of sprintf to safer snprintf This involved minor changes to private function signatures to take the size of the buffer. * Committing clang-format changes Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- hl/test/test_ds.c | 36 +++++++------- src/H5Cmpio.c | 4 +- src/H5Tdbg.c | 2 +- src/H5Z.c | 2 +- src/H5private.h | 2 +- src/H5timer.c | 39 +++++++-------- test/cache_tagging.c | 8 +-- test/cork.c | 6 +-- test/dtypes.c | 2 +- test/fheap.c | 4 +- test/filter_plugin.c | 18 +++---- test/h5test.c | 2 +- test/hyperslab.c | 55 ++++++++++----------- test/istore.c | 22 +++++---- test/lheap.c | 4 +- test/mf.c | 12 ++--- test/objcopy.c | 14 +++--- test/objcopy_ref.c | 2 +- test/ohdr.c | 2 +- test/stab.c | 29 +++++------ test/swmr_common.c | 9 ++-- test/swmr_common.h | 8 +-- test/swmr_generator.c | 2 +- test/tattr.c | 14 +++--- test/testmeta.c | 8 +-- test/tfile.c | 16 +++--- test/th5o.c | 2 +- test/titerate.c | 8 +-- test/unlink.c | 78 +++++++++++++++--------------- test/vfd.c | 20 ++++---- testpar/t_2Gio.c | 11 +++-- testpar/t_dset.c | 5 +- testpar/t_mdset.c | 30 ++++++------ testpar/t_vfd.c | 99 +++++++++++++++++++++++++------------- tools/src/h5perf/sio_engine.c | 6 +-- tools/src/h5repack/h5repack_copy.c | 6 +-- tools/src/misc/h5repart.c | 8 +-- tools/test/h5dump/h5dumpgentest.c | 30 ++++++------ tools/test/h5jam/h5jamgentest.c | 6 +-- tools/test/h5repack/h5repacktst.c | 6 +-- tools/test/h5stat/h5stat_gentest.c | 14 +++--- tools/test/misc/h5perf_gentest.c | 54 ++++++++++----------- tools/test/perform/iopipe.c | 2 +- 43 files changed, 376 insertions(+), 331 deletions(-) diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c index 12b6840..cc716aa 100644 --- a/hl/test/test_ds.c +++ b/hl/test/test_ds.c @@ -1220,14 +1220,14 @@ test_detachscales(void) /* make datasets; they are three dimensional*/ for (i = 0; i < 2; i++) { - HDsprintf(dname, "D%d", i); + HDsnprintf(dname, sizeof(dname), "D%d", i); if (H5LTmake_dataset_int(fid, dname, rank3, dims, buf) < 0) goto out; } /* create datasets and make them dim. scales */ for (i = 0; i < 4; i++) { - HDsprintf(dname, "DS%d", i); + HDsnprintf(dname, sizeof(dname), "DS%d", i); if (H5LTmake_dataset_int(fid, dname, rank1, dims, buf) < 0) goto out; } @@ -1235,7 +1235,7 @@ test_detachscales(void) two scales attached */ if ((did = H5Dopen2(fid, "D0", H5P_DEFAULT)) >= 0) { for (i = 0; i < 4; i++) { - HDsprintf(dname, "DS%d", i); + HDsnprintf(dname, sizeof(dname), "DS%d", i); if ((dsid = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0) goto out; if (H5DSattach_scale(did, dsid, (unsigned int)i % 3) < 0) @@ -1252,7 +1252,7 @@ test_detachscales(void) /* attach scales to the second dataset */ if ((did = H5Dopen2(fid, "D1", H5P_DEFAULT)) >= 0) { for (i = 0; i < 3; i++) { - HDsprintf(dname, "DS%d", i); + HDsnprintf(dname, sizeof(dname), "DS%d", i); if ((dsid = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0) goto out; if (H5DSattach_scale(did, dsid, (unsigned int)i) < 0) @@ -1273,7 +1273,7 @@ test_detachscales(void) goto out; for (i = 0; i < 2; i++) { - HDsprintf(dname, "D%d", i); + HDsnprintf(dname, sizeof(dname), "D%d", i); if ((did = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0) goto out; if (H5DSdetach_scale(did, dsid, (unsigned int)0) < 0) @@ -1303,7 +1303,7 @@ test_detachscales(void) sure that attribute "DIMENSION_LIST" doesn't exist anymore */ if ((did = H5Dopen2(fid, "D0", H5P_DEFAULT)) >= 0) { for (i = 1; i < 4; i++) { - HDsprintf(dname, "DS%d", i); + HDsnprintf(dname, sizeof(dname), "DS%d", i); if ((dsid = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0) goto out; if (H5DSdetach_scale(did, dsid, (unsigned int)i % 3) < 0) @@ -2984,10 +2984,10 @@ test_simple(void) if ((sid = H5Screate_simple(rank, dims, NULL)) < 0) goto out; for (i = 0; i < 5; i++) { - HDsprintf(dname, "dset_%d", i); + HDsnprintf(dname, sizeof(dname), "dset_%d", i); if ((did = H5Dcreate2(gid, dname, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; - HDsprintf(sname, "ds_%d", i); + HDsnprintf(sname, sizeof(sname), "ds_%d", i); if ((dsid = H5Dcreate2(gid, sname, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; if (H5DSset_scale(dsid, "scale") < 0) @@ -3004,11 +3004,11 @@ test_simple(void) */ for (i = 0; i < 5; i++) { - HDsprintf(dname, "dset_%d", i); + HDsnprintf(dname, sizeof(dname), "dset_%d", i); if ((did = H5Dopen2(gid, dname, H5P_DEFAULT)) < 0) goto out; for (j = 0; j < 5; j++) { - HDsprintf(sname, "ds_%d", j); + HDsnprintf(sname, sizeof(sname), "ds_%d", j); if ((dsid = H5Dopen2(gid, sname, H5P_DEFAULT)) < 0) goto out; if (H5DSattach_scale(did, dsid, DIM0) < 0) @@ -3026,11 +3026,11 @@ test_simple(void) */ for (i = 0; i < 5; i++) { - HDsprintf(dname, "dset_%d", i); + HDsnprintf(dname, sizeof(dname), "dset_%d", i); if ((did = H5Dopen2(gid, dname, H5P_DEFAULT)) < 0) goto out; for (j = 0; j < 5; j++) { - HDsprintf(sname, "ds_%d", j); + HDsnprintf(sname, sizeof(sname), "ds_%d", j); if ((dsid = H5Dopen2(gid, sname, H5P_DEFAULT)) < 0) goto out; if (H5DSdetach_scale(did, dsid, DIM0) < 0) @@ -3048,11 +3048,11 @@ test_simple(void) */ for (i = 0; i < 5; i++) { - HDsprintf(dname, "dset_%d", i); + HDsnprintf(dname, sizeof(dname), "dset_%d", i); if ((did = H5Dopen2(gid, dname, H5P_DEFAULT)) < 0) goto out; for (j = 0; j < 5; j++) { - HDsprintf(sname, "ds_%d", j); + HDsnprintf(sname, sizeof(sname), "ds_%d", j); if ((dsid = H5Dopen2(gid, sname, H5P_DEFAULT)) < 0) goto out; if (H5DSattach_scale(did, dsid, DIM0) < 0) @@ -4292,7 +4292,7 @@ test_iterators(void) for (i = 0; i < 100; i++) { /* make a DS */ - HDsprintf(dname, "ds_%d", i); + HDsnprintf(dname, sizeof(dname), "ds_%d", i); if (H5LTmake_dataset_int(fid, dname, rankds, s1_dim, NULL) < 0) goto out; /* open */ @@ -4442,7 +4442,7 @@ test_rank(void) goto out; for (i = 0; i < 3; i++) { - HDsprintf(name, "ds_a_%d", i); + HDsnprintf(name, sizeof(name), "ds_a_%d", i); if ((dsid = H5Dopen2(fid, name, H5P_DEFAULT)) < 0) goto out; if (H5DSattach_scale(did, dsid, (unsigned)i) < 0) @@ -4469,7 +4469,7 @@ test_rank(void) goto out; for (i = 0; i < 3; i++) { - HDsprintf(name, "ds_a_%d", i); + HDsnprintf(name, sizeof(name), "ds_a_%d", i); if ((dsid = H5Dopen2(fid, name, H5P_DEFAULT)) < 0) goto out; if (H5DSdetach_scale(did, dsid, (unsigned)i) < 0) @@ -4495,7 +4495,7 @@ test_rank(void) goto out; for (i = 0; i < 3; i++) { - HDsprintf(name, "ds_a_%d", i); + HDsnprintf(name, sizeof(name), "ds_a_%d", i); if ((dsid = H5Dopen2(fid, name, H5P_DEFAULT)) < 0) goto out; if (H5DSset_scale(dsid, name) < 0) diff --git a/src/H5Cmpio.c b/src/H5Cmpio.c index a0cc6bb..a746e54 100644 --- a/src/H5Cmpio.c +++ b/src/H5Cmpio.c @@ -199,7 +199,7 @@ H5C_apply_candidate_list(H5F_t *f, H5C_t *cache_ptr, unsigned num_candidates, ha HDmemset(tbl_buf, 0, sizeof(tbl_buf)); - HDsprintf(&(tbl_buf[0]), "candidate list = "); + HDsnprintf(tbl_buf, sizeof(tbl_buf), "candidate list = "); for (u = 0; u < num_candidates; u++) HDsprintf(&(tbl_buf[HDstrlen(tbl_buf)]), " 0x%llx", (long long)(*(candidates_list_ptr + u))); HDsprintf(&(tbl_buf[HDstrlen(tbl_buf)]), "\n"); @@ -266,7 +266,7 @@ H5C_apply_candidate_list(H5F_t *f, H5C_t *cache_ptr, unsigned num_candidates, ha #if H5C_APPLY_CANDIDATE_LIST__DEBUG for (u = 0; u < 1024; u++) tbl_buf[u] = '\0'; - HDsprintf(&(tbl_buf[0]), "candidate assignment table = "); + HDsnprintf(tbl_buf, sizeof(tbl_buf), "candidate assignment table = "); for (u = 0; u <= (unsigned)mpi_size; u++) HDsprintf(&(tbl_buf[HDstrlen(tbl_buf)]), " %u", candidate_assignment_table[u]); HDsprintf(&(tbl_buf[HDstrlen(tbl_buf)]), "\n"); diff --git a/src/H5Tdbg.c b/src/H5Tdbg.c index 613aa60..515b710 100644 --- a/src/H5Tdbg.c +++ b/src/H5Tdbg.c @@ -116,7 +116,7 @@ H5T__print_stats(H5T_path_t H5_ATTR_UNUSED *path, int H5_ATTR_UNUSED *nprint /*i else nbytes = 0; nbytes *= path->stats.nelmts; - H5_bandwidth(bandwidth, (double)nbytes, path->stats.times.elapsed); + H5_bandwidth(bandwidth, sizeof(bandwidth), (double)nbytes, path->stats.times.elapsed); HDfprintf(H5DEBUG(T), " %-16s %10" PRIdHSIZE " %10u %8s %8s %8s %10s\n", path->name, path->stats.nelmts, path->stats.ncalls, timestrs.user, timestrs.system, timestrs.elapsed, bandwidth); diff --git a/src/H5Z.c b/src/H5Z.c index d7ccbb4..23eb731 100644 --- a/src/H5Z.c +++ b/src/H5Z.c @@ -166,7 +166,7 @@ H5Z_term_package(void) * units of `B/s', `kB/s', `MB/s', `GB/s', or `TB/s' or * the word `Inf' if the elapsed time is zero. */ - H5_bandwidth(bandwidth, (double)(H5Z_stat_table_g[i].stats[dir].total), + H5_bandwidth(bandwidth, sizeof(bandwidth), (double)(H5Z_stat_table_g[i].stats[dir].total), H5Z_stat_table_g[i].stats[dir].times.elapsed); /* Print the statistics */ diff --git a/src/H5private.h b/src/H5private.h index 974f26c..c8653b7 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -550,7 +550,7 @@ typedef struct { } H5_timer_t; /* Returns library bandwidth as a pretty string */ -H5_DLL void H5_bandwidth(char *buf /*out*/, double nbytes, double nseconds); +H5_DLL void H5_bandwidth(char *buf /*out*/, size_t bufsize, double nbytes, double nseconds); /* Timer functionality */ H5_DLL time_t H5_now(void); diff --git a/src/H5timer.c b/src/H5timer.c index b5dba97..83fd243 100644 --- a/src/H5timer.c +++ b/src/H5timer.c @@ -96,7 +96,7 @@ *------------------------------------------------------------------------- */ void -H5_bandwidth(char *buf /*out*/, double nbytes, double nseconds) +H5_bandwidth(char *buf /*out*/, size_t bufsize, double nbytes, double nseconds) { double bw; @@ -107,35 +107,35 @@ H5_bandwidth(char *buf /*out*/, double nbytes, double nseconds) if (H5_DBL_ABS_EQUAL(bw, 0.0)) HDstrcpy(buf, "0.000 B/s"); else if (bw < 1.0) - HDsprintf(buf, "%10.4e", bw); + HDsnprintf(buf, bufsize, "%10.4e", bw); else if (bw < (double)H5_KB) { - HDsprintf(buf, "%05.4f", bw); + HDsnprintf(buf, bufsize, "%05.4f", bw); HDstrcpy(buf + 5, " B/s"); } else if (bw < (double)H5_MB) { - HDsprintf(buf, "%05.4f", bw / (double)H5_KB); + HDsnprintf(buf, bufsize, "%05.4f", bw / (double)H5_KB); HDstrcpy(buf + 5, " kB/s"); } else if (bw < (double)H5_GB) { - HDsprintf(buf, "%05.4f", bw / (double)H5_MB); + HDsnprintf(buf, bufsize, "%05.4f", bw / (double)H5_MB); HDstrcpy(buf + 5, " MB/s"); } else if (bw < (double)H5_TB) { - HDsprintf(buf, "%05.4f", bw / (double)H5_GB); + HDsnprintf(buf, bufsize, "%05.4f", bw / (double)H5_GB); HDstrcpy(buf + 5, " GB/s"); } else if (bw < (double)H5_PB) { - HDsprintf(buf, "%05.4f", bw / (double)H5_TB); + HDsnprintf(buf, bufsize, "%05.4f", bw / (double)H5_TB); HDstrcpy(buf + 5, " TB/s"); } else if (bw < (double)H5_EB) { - HDsprintf(buf, "%05.4f", bw / (double)H5_PB); + HDsnprintf(buf, bufsize, "%05.4f", bw / (double)H5_PB); HDstrcpy(buf + 5, " PB/s"); } else { - HDsprintf(buf, "%10.4e", bw); + HDsnprintf(buf, bufsize, "%10.4e", bw); if (HDstrlen(buf) > 10) - HDsprintf(buf, "%10.3e", bw); + HDsnprintf(buf, bufsize, "%10.3e", bw); } /* end else-if */ } /* end else */ } /* end H5_bandwidth() */ @@ -627,30 +627,31 @@ H5_timer_get_time_string(double seconds) * (name? round_up_size? ?) */ if (seconds < 0.0) - HDsprintf(s, "N/A"); + HDsnprintf(s, H5TIMER_TIME_STRING_LEN, "N/A"); else if (H5_DBL_ABS_EQUAL(0.0, seconds)) - HDsprintf(s, "0.0 s"); + HDsnprintf(s, H5TIMER_TIME_STRING_LEN, "0.0 s"); else if (seconds < 1.0E-6) /* t < 1 us, Print time in ns */ - HDsprintf(s, "%.f ns", seconds * 1.0E9); + HDsnprintf(s, H5TIMER_TIME_STRING_LEN, "%.f ns", seconds * 1.0E9); else if (seconds < 1.0E-3) /* t < 1 ms, Print time in us */ - HDsprintf(s, "%.1f us", seconds * 1.0E6); + HDsnprintf(s, H5TIMER_TIME_STRING_LEN, "%.1f us", seconds * 1.0E6); else if (seconds < 1.0) /* t < 1 s, Print time in ms */ - HDsprintf(s, "%.1f ms", seconds * 1.0E3); + HDsnprintf(s, H5TIMER_TIME_STRING_LEN, "%.1f ms", seconds * 1.0E3); else if (seconds < H5_SEC_PER_MIN) /* t < 1 m, Print time in s */ - HDsprintf(s, "%.2f s", seconds); + HDsnprintf(s, H5TIMER_TIME_STRING_LEN, "%.2f s", seconds); else if (seconds < H5_SEC_PER_HOUR) /* t < 1 h, Print time in m and s */ - HDsprintf(s, "%.f m %.f s", minutes, remainder_sec); + HDsnprintf(s, H5TIMER_TIME_STRING_LEN, "%.f m %.f s", minutes, remainder_sec); else if (seconds < H5_SEC_PER_DAY) /* t < 1 d, Print time in h, m and s */ - HDsprintf(s, "%.f h %.f m %.f s", hours, minutes, remainder_sec); + HDsnprintf(s, H5TIMER_TIME_STRING_LEN, "%.f h %.f m %.f s", hours, minutes, remainder_sec); else /* Print time in d, h, m and s */ - HDsprintf(s, "%.f d %.f h %.f m %.f s", days, hours, minutes, remainder_sec); + HDsnprintf(s, H5TIMER_TIME_STRING_LEN, "%.f d %.f h %.f m %.f s", days, hours, minutes, + remainder_sec); return s; } /* end H5_timer_get_time_string() */ diff --git a/test/cache_tagging.c b/test/cache_tagging.c index 4d07116..f1571f0 100644 --- a/test/cache_tagging.c +++ b/test/cache_tagging.c @@ -839,7 +839,7 @@ check_multi_group_creation_tags(void) for (i = 0; i < MULTIGROUPS; i++) { - HDsprintf(gname, "%d", i); + HDsnprintf(gname, sizeof(gname), "%d", i); if ((gid = H5Gcreate2(fid, gname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; if (H5Gclose(gid) < 0) @@ -861,7 +861,7 @@ check_multi_group_creation_tags(void) for (i = 0; i < MULTIGROUPS; i++) { /* Re-open the group */ - HDsprintf(gname, "%d", i); + HDsnprintf(gname, sizeof(gname), "%d", i); if ((gid = H5Gopen2(fid, gname, H5P_DEFAULT)) < 0) TEST_ERROR; @@ -988,7 +988,7 @@ check_link_iteration_tags(void) /* Create many datasets in root group */ for (i = 0; i < 500; i++) { - HDsprintf(dsetname, "Dset %d", i); + HDsnprintf(dsetname, sizeof(dsetname), "Dset %d", i); if ((did = H5Dcreate2(fid, dsetname, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; @@ -1151,7 +1151,7 @@ check_dense_attribute_tags(void) for (i = 0; i < 50; i++) { - HDsprintf(attrname, "attr %d", i); + HDsnprintf(attrname, sizeof(attrname), "attr %d", i); if ((aid = H5Acreate2(did, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; if (H5Awrite(aid, H5T_NATIVE_UINT, &i) < 0) diff --git a/test/cork.c b/test/cork.c index 7628d28..53d9065 100644 --- a/test/cork.c +++ b/test/cork.c @@ -396,7 +396,7 @@ verify_obj_dset_cork(hbool_t swmr) /* Attach 8 attributes to the dataset */ for (i = 0; i < 8; i++) { - HDsprintf(attrname, "attr %d", i); + HDsnprintf(attrname, sizeof(attrname), "attr %d", i); if ((aid = H5Acreate2(did2, attrname, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; if (H5Awrite(aid, H5T_NATIVE_INT, &i) < 0) @@ -864,7 +864,7 @@ verify_group_cork(hbool_t swmr) /* Attach 8 attributes to the third group: GRP3 */ for (i = 0; i < 8; i++) { - HDsprintf(attrname, "attr %d", i); + HDsnprintf(attrname, sizeof(attrname), "attr %d", i); if ((aid = H5Acreate2(gid3, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; if (H5Awrite(aid, H5T_NATIVE_UINT, &i) < 0) @@ -1081,7 +1081,7 @@ verify_named_cork(hbool_t swmr) /* Attach 8 attributes to datatype: DT3 */ for (i = 0; i < 8; i++) { - HDsprintf(attrname, "attr %d", i); + HDsnprintf(attrname, sizeof(attrname), "attr %d", i); if ((aid = H5Acreate2(tid3, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; if (H5Awrite(aid, H5T_NATIVE_UINT, &i) < 0) diff --git a/test/dtypes.c b/test/dtypes.c index 218c019..f322d03 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -2322,7 +2322,7 @@ test_compound_11(void) ((big_t *)buf)[u].s1 = (char *)HDmalloc((size_t)32); if (!((big_t *)buf)[u].s1) TEST_ERROR; - HDsprintf(((big_t *)buf)[u].s1, "%u", (unsigned)u); + HDsnprintf(((big_t *)buf)[u].s1, 32, "%u", (unsigned)u); } /* end for */ /* Make copy of buffer before conversion */ diff --git a/test/fheap.c b/test/fheap.c index 01de37f..7fec567 100644 --- a/test/fheap.c +++ b/test/fheap.c @@ -7669,7 +7669,7 @@ test_man_incr_insert_remove(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_ if (H5HF_remove(fh, heap_id[j]) < 0) FAIL_STACK_ERROR; - HDsprintf(obj2.b, "%s%2d", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", j); + HDsnprintf(obj2.b, sizeof(obj2.b), "%s%2d", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", j); if (H5HF_insert(fh, (sizeof(obj2)), &obj2, heap_id[j]) < 0) FAIL_STACK_ERROR; } /* end for */ @@ -7680,7 +7680,7 @@ test_man_incr_insert_remove(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_ /* Insert object */ HDmemset(heap_id[i], 0, id_len); - HDsprintf(obj1.b, "%s%2d", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", i); + HDsnprintf(obj1.b, sizeof(obj1.b), "%s%2d", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", i); if (H5HF_insert(fh, (sizeof(obj1)), &obj1, heap_id[i]) < 0) FAIL_STACK_ERROR; } /* end for */ diff --git a/test/filter_plugin.c b/test/filter_plugin.c index abbcc26..4dcf74a 100644 --- a/test/filter_plugin.c +++ b/test/filter_plugin.c @@ -847,7 +847,7 @@ test_creating_groups_using_plugins(hid_t fid) for (i = 0; i < N_SUBGROUPS; i++) { char *sp = subgroup_name; - sp += HDsprintf(subgroup_name, SUBGROUP_PREFIX); + sp += HDsnprintf(subgroup_name, sizeof(subgroup_name), SUBGROUP_PREFIX); HDsprintf(sp, "%d", i); if ((sub_gid = H5Gcreate2(gid, subgroup_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) @@ -906,7 +906,7 @@ test_opening_groups_using_plugins(hid_t fid) for (i = 0; i < N_SUBGROUPS; i++) { char *sp = subgroup_name; - sp += HDsprintf(subgroup_name, SUBGROUP_PREFIX); + sp += HDsnprintf(subgroup_name, sizeof(subgroup_name), SUBGROUP_PREFIX); HDsprintf(sp, "%d", i); if ((sub_gid = H5Gopen2(gid, subgroup_name, H5P_DEFAULT)) < 0) @@ -1015,7 +1015,7 @@ test_path_api_calls(void) /* Add a bunch of paths to the path table */ for (u = 0; u < n_starting_paths; u++) { - HDsprintf(path, "a_path_%u", u); + HDsnprintf(path, sizeof(path), "a_path_%u", u); if (H5PLappend(path) < 0) { HDfprintf(stderr, " at %u: %s\n", u, path); TEST_ERROR; @@ -1081,7 +1081,7 @@ test_path_api_calls(void) /* Get path at the last index */ if ((path_len = H5PLget(n_starting_paths - 1, path, 256)) <= 0) TEST_ERROR; - HDsprintf(temp_name, "a_path_%u", n_starting_paths - 1); + HDsnprintf(temp_name, sizeof(temp_name), "a_path_%u", n_starting_paths - 1); if (HDstrcmp(path, temp_name) != 0) { HDfprintf(stderr, " get %u: %s\n", n_starting_paths - 1, path); TEST_ERROR; @@ -1135,7 +1135,7 @@ test_path_api_calls(void) TESTING(" prepend"); /* Prepend one path */ - HDsprintf(path, "a_path_%d", n_starting_paths + 1); + HDsnprintf(path, sizeof(path), "a_path_%d", n_starting_paths + 1); if (H5PLprepend(path) < 0) { HDfprintf(stderr, " prepend %u: %s\n", n_starting_paths + 1, path); TEST_ERROR; @@ -1158,7 +1158,7 @@ test_path_api_calls(void) /* Verify that the path was inserted at index zero */ if (H5PLget(0, path, 256) <= 0) TEST_ERROR; - HDsprintf(temp_name, "a_path_%d", n_starting_paths + 1); + HDsnprintf(temp_name, sizeof(temp_name), "a_path_%d", n_starting_paths + 1); if (HDstrcmp(path, temp_name) != 0) { HDfprintf(stderr, " get 0: %s\n", path); TEST_ERROR; @@ -1173,7 +1173,7 @@ test_path_api_calls(void) TESTING(" replace"); /* Replace one path at index 1 */ - HDsprintf(path, "a_path_%u", n_starting_paths + 4); + HDsnprintf(path, sizeof(path), "a_path_%u", n_starting_paths + 4); if (H5PLreplace(path, 1) < 0) { HDfprintf(stderr, " replace 1: %s\n", path); TEST_ERROR; @@ -1192,7 +1192,7 @@ test_path_api_calls(void) /* Check path at index 0 */ if (H5PLget(0, path, 256) <= 0) TEST_ERROR; - HDsprintf(temp_name, "a_path_%u", n_starting_paths + 1); + HDsnprintf(temp_name, sizeof(temp_name), "a_path_%u", n_starting_paths + 1); if (HDstrcmp(path, temp_name) != 0) { HDfprintf(stderr, " get 0: %s\n", path); TEST_ERROR; @@ -1240,7 +1240,7 @@ test_path_api_calls(void) TESTING(" insert"); /* Insert one path at index 3*/ - HDsprintf(path, "a_path_%d", n_starting_paths + 5); + HDsnprintf(path, sizeof(path), "a_path_%d", n_starting_paths + 5); if (H5PLinsert(path, 3) < 0) { HDfprintf(stderr, " insert 3: %s\n", path); TEST_ERROR; diff --git a/test/h5test.c b/test/h5test.c index ac15043..f39825c 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -355,7 +355,7 @@ h5_reset(void) * Cause the library to emit some diagnostics early so they don't * interfere with other formatted output. */ - HDsprintf(filename, "/tmp/h5emit-%05d.h5", HDgetpid()); + HDsnprintf(filename, sizeof(filename), "/tmp/h5emit-%05d.h5", HDgetpid()); H5E_BEGIN_TRY { hid_t file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); diff --git a/test/hyperslab.c b/test/hyperslab.c index 36e6b65..b816aae 100644 --- a/test/hyperslab.c +++ b/test/hyperslab.c @@ -163,19 +163,19 @@ test_fill(size_t nx, size_t ny, size_t nz, size_t di, size_t dj, size_t dk, size if (0 == ny) { ndims = 1; ny = nz = 1; - HDsprintf(dim, "%lu", (unsigned long)nx); + HDsnprintf(dim, sizeof(dim), "%lu", (unsigned long)nx); } /* end if */ else { ndims = 2; nz = 1; - HDsprintf(dim, "%lux%lu", (unsigned long)nx, (unsigned long)ny); + HDsnprintf(dim, sizeof(dim), "%lux%lu", (unsigned long)nx, (unsigned long)ny); } /* end else */ } /* end if */ else { ndims = 3; - HDsprintf(dim, "%lux%lux%lu", (unsigned long)nx, (unsigned long)ny, (unsigned long)nz); + HDsnprintf(dim, sizeof(dim), "%lux%lux%lu", (unsigned long)nx, (unsigned long)ny, (unsigned long)nz); } /* end else */ - HDsprintf(s, "Testing hyperslab fill %-11s variable hyperslab", dim); + HDsnprintf(s, sizeof(s), "Testing hyperslab fill %-11s variable hyperslab", dim); HDprintf("%-70s", s); HDfflush(stdout); @@ -321,17 +321,17 @@ test_copy(int mode, size_t nx, size_t ny, size_t nz, size_t di, size_t dj, size_ if (0 == ny) { ndims = 1; ny = nz = 1; - HDsprintf(dim, "%lu", (unsigned long)nx); + HDsnprintf(dim, sizeof(dim), "%lu", (unsigned long)nx); } /* end if */ else { ndims = 2; nz = 1; - HDsprintf(dim, "%lux%lu", (unsigned long)nx, (unsigned long)ny); + HDsnprintf(dim, sizeof(dim), "%lux%lu", (unsigned long)nx, (unsigned long)ny); } /* end else */ } /* end if */ else { ndims = 3; - HDsprintf(dim, "%lux%lux%lu", (unsigned long)nx, (unsigned long)ny, (unsigned long)nz); + HDsnprintf(dim, sizeof(dim), "%lux%lux%lu", (unsigned long)nx, (unsigned long)ny, (unsigned long)nz); } /* end else */ switch (mode) { @@ -364,7 +364,7 @@ test_copy(int mode, size_t nx, size_t ny, size_t nz, size_t di, size_t dj, size_ HDabort(); } /* end switch */ - HDsprintf(s, "Testing hyperslab copy %-11s %s", dim, sub); + HDsnprintf(s, sizeof(s), "Testing hyperslab copy %-11s %s", dim, sub); HDprintf("%-70s", s); HDfflush(stdout); @@ -618,15 +618,15 @@ test_multifill(size_t nx) s[0] = '\0'; for (i = 0; i < nx; i++) { if (dst[i].left != 3333333) - HDsprintf(s, "bad dst[%lu].left", (unsigned long)i); + HDsnprintf(s, sizeof(s), "bad dst[%lu].left", (unsigned long)i); else if (!H5_DBL_ABS_EQUAL(dst[i].mid, fill.mid)) /* Check if two DOUBLE values are equal. If their difference * is smaller than the EPSILON value for double, they are * considered equal. See the definition in h5test.h. */ - HDsprintf(s, "bad dst[%lu].mid", (unsigned long)i); + HDsnprintf(s, sizeof(s), "bad dst[%lu].mid", (unsigned long)i); else if (dst[i].right != 4444444) - HDsprintf(s, "bad dst[%lu].right", (unsigned long)i); + HDsnprintf(s, sizeof(s), "bad dst[%lu].right", (unsigned long)i); if (s[0]) { H5_FAILED(); if (!HDisatty(1)) { @@ -771,7 +771,8 @@ test_transpose(size_t nx, size_t ny) char s[256]; hsize_t i, j; - HDsprintf(s, "Testing 2d transpose by stride %4lux%-lud", (unsigned long)nx, (unsigned long)ny); + HDsnprintf(s, sizeof(s), "Testing 2d transpose by stride %4lux%-lud", (unsigned long)nx, + (unsigned long)ny); HDprintf("%-70s", s); HDfflush(stdout); @@ -869,8 +870,8 @@ test_sub_super(size_t nx, size_t ny) hsize_t i, j; char s[256]; - HDsprintf(s, "Testing image sampling %4lux%-4lu to %4lux%-4lu ", (unsigned long)(2 * nx), - (unsigned long)(2 * ny), (unsigned long)nx, (unsigned long)ny); + HDsnprintf(s, sizeof(s), "Testing image sampling %4lux%-4lu to %4lux%-4lu ", (unsigned long)(2 * nx), + (unsigned long)(2 * ny), (unsigned long)nx, (unsigned long)ny); HDprintf("%-70s", s); HDfflush(stdout); @@ -919,8 +920,8 @@ test_sub_super(size_t nx, size_t ny) * Test replicating pixels to produce an image twice as large in each * dimension. */ - HDsprintf(s, "Testing image sampling %4lux%-4lu to %4lux%-4lu ", (unsigned long)nx, (unsigned long)ny, - (unsigned long)(2 * nx), (unsigned long)(2 * ny)); + HDsnprintf(s, sizeof(s), "Testing image sampling %4lux%-4lu to %4lux%-4lu ", (unsigned long)nx, + (unsigned long)ny, (unsigned long)(2 * nx), (unsigned long)(2 * ny)); HDprintf("%-70s", s); HDfflush(stdout); @@ -946,17 +947,17 @@ test_sub_super(size_t nx, size_t ny) for (i = 0; i < nx; i++) { for (j = 0; j < ny; j++) { if (half[i * ny + j] != twice[4 * i * ny + 2 * j]) - HDsprintf(s, "half[%lu][%lu] != twice[%lu][%lu]", (unsigned long)i, (unsigned long)j, - (unsigned long)i * 2, (unsigned long)j * 2); + HDsnprintf(s, sizeof(s), "half[%lu][%lu] != twice[%lu][%lu]", (unsigned long)i, + (unsigned long)j, (unsigned long)i * 2, (unsigned long)j * 2); else if (half[i * ny + j] != twice[4 * i * ny + 2 * j + 1]) - HDsprintf(s, "half[%lu][%lu] != twice[%lu][%lu]", (unsigned long)i, (unsigned long)j, - (unsigned long)i * 2, (unsigned long)j * 2 + 1); + HDsnprintf(s, sizeof(s), "half[%lu][%lu] != twice[%lu][%lu]", (unsigned long)i, + (unsigned long)j, (unsigned long)i * 2, (unsigned long)j * 2 + 1); else if (half[i * ny + j] != twice[(2 * i + 1) * 2 * ny + 2 * j]) - HDsprintf(s, "half[%lu][%lu] != twice[%lu][%lu]", (unsigned long)i, (unsigned long)j, - (unsigned long)i * 2 + 1, (unsigned long)j * 2); + HDsnprintf(s, sizeof(s), "half[%lu][%lu] != twice[%lu][%lu]", (unsigned long)i, + (unsigned long)j, (unsigned long)i * 2 + 1, (unsigned long)j * 2); else if (half[i * ny + j] != twice[(2 * i + 1) * 2 * ny + 2 * j + 1]) - HDsprintf(s, "half[%lu][%lu] != twice[%lu][%lu]", (unsigned long)i, (unsigned long)j, - (unsigned long)i * 2 + 1, (unsigned long)j * 2 + 1); + HDsnprintf(s, sizeof(s), "half[%lu][%lu] != twice[%lu][%lu]", (unsigned long)i, + (unsigned long)j, (unsigned long)i * 2 + 1, (unsigned long)j * 2 + 1); if (s[0]) { H5_FAILED(); if (!HDisatty(1)) { @@ -1014,7 +1015,7 @@ test_array_fill(size_t lo, size_t hi) size_t u, v, w; /* Local index variables */ char s[256]; - HDsprintf(s, "array filling %4lu-%-4lu elements", (unsigned long)lo, (unsigned long)hi); + HDsnprintf(s, sizeof(s), "array filling %4lu-%-4lu elements", (unsigned long)lo, (unsigned long)hi); TESTING(s); /* Initialize */ @@ -1078,8 +1079,8 @@ test_array_offset_n_calc(size_t n, size_t x, size_t y, size_t z) hsize_t new_coords[ARRAY_OFFSET_NDIMS]; /* X, Y & X coordinates of offset */ char s[256]; - HDsprintf(s, "array offset %4lux%4lux%4lu elements", (unsigned long)z, (unsigned long)y, - (unsigned long)x); + HDsnprintf(s, sizeof(s), "array offset %4lux%4lux%4lu elements", (unsigned long)z, (unsigned long)y, + (unsigned long)x); TESTING(s); /* Initialize */ diff --git a/test/istore.c b/test/istore.c index f198aad..144355e 100644 --- a/test/istore.c +++ b/test/istore.c @@ -271,20 +271,21 @@ test_extend(hid_t f, const char *prefix, size_t nx, size_t ny, size_t nz) if (!ny) { ndims = 1; ny = nz = 1; - HDsprintf(dims, "%lu", (unsigned long)nx); + HDsnprintf(dims, sizeof(dims), "%lu", (unsigned long)nx); } else { ndims = 2; nz = 1; - HDsprintf(dims, "%lux%lu", (unsigned long)nx, (unsigned long)ny); + HDsnprintf(dims, sizeof(dims), "%lux%lu", (unsigned long)nx, (unsigned long)ny); } } else { ndims = 3; - HDsprintf(dims, "%lux%lux%lu", (unsigned long)nx, (unsigned long)ny, (unsigned long)nz); + HDsnprintf(dims, sizeof(dims), "%lux%lux%lu", (unsigned long)nx, (unsigned long)ny, + (unsigned long)nz); } - HDsprintf(s, "istore extend: %s", dims); + HDsnprintf(s, sizeof(s), "istore extend: %s", dims); TESTING(s); buf = (uint8_t *)HDmalloc(nx * ny * nz); check = (uint8_t *)HDmalloc(nx * ny * nz); @@ -298,7 +299,7 @@ test_extend(hid_t f, const char *prefix, size_t nx, size_t ny, size_t nz) max_corner[2] = 0; /* Build the new empty object */ - HDsprintf(name, "%s_%s", prefix, dims); + HDsnprintf(name, sizeof(name), "%s_%s", prefix, dims); if ((dataset = new_object(f, name, ndims, whole_size, whole_size)) < 0) { HDfprintf(stderr, " Cannot create %u-d object `%s'\n", ndims, name); goto error; @@ -468,20 +469,21 @@ test_sparse(hid_t f, const char *prefix, size_t nblocks, size_t nx, size_t ny, s if (!ny) { ndims = 1; ny = nz = 1; - HDsprintf(dims, "%lu", (unsigned long)nx); + HDsnprintf(dims, sizeof(dims), "%lu", (unsigned long)nx); } else { ndims = 2; nz = 1; - HDsprintf(dims, "%lux%lu", (unsigned long)nx, (unsigned long)ny); + HDsnprintf(dims, sizeof(dims), "%lux%lu", (unsigned long)nx, (unsigned long)ny); } } else { ndims = 3; - HDsprintf(dims, "%lux%lux%lu", (unsigned long)nx, (unsigned long)ny, (unsigned long)nz); + HDsnprintf(dims, sizeof(dims), "%lux%lux%lu", (unsigned long)nx, (unsigned long)ny, + (unsigned long)nz); } - HDsprintf(s, "istore sparse: %s", dims); + HDsnprintf(s, sizeof(s), "istore sparse: %s", dims); TESTING(s); if (skip_test) { SKIPPED(); @@ -500,7 +502,7 @@ test_sparse(hid_t f, const char *prefix, size_t nblocks, size_t nx, size_t ny, s size[2] = nz; /* Build the new empty object */ - HDsprintf(name, "%s_%s", prefix, dims); + HDsnprintf(name, sizeof(name), "%s_%s", prefix, dims); if ((dataset = new_object(f, name, ndims, whole_size, chunk_dims)) < 0) { HDprintf(" Cannot create %u-d object `%s'\n", ndims, name); goto error; diff --git a/test/lheap.c b/test/lheap.c index 1c6a6df..c9c6ca9 100644 --- a/test/lheap.c +++ b/test/lheap.c @@ -97,7 +97,7 @@ main(void) goto error; } for (i = 0; i < NOBJS; i++) { - HDsprintf(buf, "%03d-", i); + HDsnprintf(buf, sizeof(buf), "%03d-", i); for (j = 4; j < i; j++) buf[j] = (char)('0' + j % 10); if (j > 4) @@ -137,7 +137,7 @@ main(void) goto error; } for (i = 0; i < NOBJS; i++) { - HDsprintf(buf, "%03d-", i); + HDsnprintf(buf, sizeof(buf), "%03d-", i); for (j = 4; j < i; j++) buf[j] = (char)('0' + j % 10); if (j > 4) diff --git a/test/mf.c b/test/mf.c index ce9d667..bed92e3 100644 --- a/test/mf.c +++ b/test/mf.c @@ -6586,22 +6586,22 @@ error: memb_map[H5FD_MEM_DRAW] = H5FD_MEM_DRAW; \ memb_map[H5FD_MEM_GHEAP] = H5FD_MEM_GHEAP; \ memb_map[H5FD_MEM_LHEAP] = H5FD_MEM_LHEAP; \ - HDsprintf(sv[H5FD_MEM_SUPER], "%%s-%c.h5", 's'); \ + HDsnprintf(sv[H5FD_MEM_SUPER], 64, "%%s-%c.h5", 's'); \ memb_name[H5FD_MEM_SUPER] = sv[H5FD_MEM_SUPER]; \ memb_addr[H5FD_MEM_SUPER] = 0; \ - HDsprintf(sv[H5FD_MEM_BTREE], "%%s-%c.h5", 'b'); \ + HDsnprintf(sv[H5FD_MEM_BTREE], 64, "%%s-%c.h5", 'b'); \ memb_name[H5FD_MEM_BTREE] = sv[H5FD_MEM_BTREE]; \ memb_addr[H5FD_MEM_BTREE] = HADDR_MAX / 6; \ - HDsprintf(sv[H5FD_MEM_DRAW], "%%s-%c.h5", 'r'); \ + HDsnprintf(sv[H5FD_MEM_DRAW], 64, "%%s-%c.h5", 'r'); \ memb_name[H5FD_MEM_DRAW] = sv[H5FD_MEM_DRAW]; \ memb_addr[H5FD_MEM_DRAW] = HADDR_MAX / 3; \ - HDsprintf(sv[H5FD_MEM_GHEAP], "%%s-%c.h5", 'g'); \ + HDsnprintf(sv[H5FD_MEM_GHEAP], 64, "%%s-%c.h5", 'g'); \ memb_name[H5FD_MEM_GHEAP] = sv[H5FD_MEM_GHEAP]; \ memb_addr[H5FD_MEM_GHEAP] = HADDR_MAX / 2; \ - HDsprintf(sv[H5FD_MEM_LHEAP], "%%s-%c.h5", 'l'); \ + HDsnprintf(sv[H5FD_MEM_LHEAP], 64, "%%s-%c.h5", 'l'); \ memb_name[H5FD_MEM_LHEAP] = sv[H5FD_MEM_LHEAP]; \ memb_addr[H5FD_MEM_LHEAP] = HADDR_MAX * 2 / 3; \ - HDsprintf(sv[H5FD_MEM_OHDR], "%%s-%c.h5", 'o'); \ + HDsnprintf(sv[H5FD_MEM_OHDR], 64, "%%s-%c.h5", 'o'); \ memb_name[H5FD_MEM_OHDR] = sv[H5FD_MEM_OHDR]; \ memb_addr[H5FD_MEM_OHDR] = HADDR_MAX * 5 / 6; \ } diff --git a/test/objcopy.c b/test/objcopy.c index cc8f428..62fb22e 100644 --- a/test/objcopy.c +++ b/test/objcopy.c @@ -646,7 +646,7 @@ test_copy_attach_attributes(hid_t loc_id, hid_t type_id) goto done; for (u = 0; u < num_attributes_g; u++) { - HDsprintf(attr_name, "%u attr", u); + HDsnprintf(attr_name, sizeof(attr_name), "%u attr", u); /* Set attribute data */ attr_data[0] = (int)(100 * u); @@ -715,7 +715,7 @@ test_copy_attach_paired_attributes(hid_t loc_id, hid_t loc_id2, hid_t type_id) goto done; for (u = 0; u < num_attributes_g; u++) { - HDsprintf(attr_name, "%u attr", u); + HDsnprintf(attr_name, sizeof(attr_name), "%u attr", u); /* Set attribute data */ attr_data[0] = (int)(100 * u); @@ -7933,17 +7933,17 @@ test_copy_group_deep(hid_t fcpl_src, hid_t fcpl_dst, hid_t src_fapl, hid_t dst_f /* create nested sub-groups & datasets */ for (i = 0; i < NUM_SUB_GROUPS; i++) { - HDsprintf(objname, "Group #%d", i); + HDsnprintf(objname, sizeof(objname), "Group #%d", i); if ((gid_sub = H5Gcreate2(gid, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; for (j = 0; j < NUM_SUB_GROUPS; j++) { - HDsprintf(objname, "Group #%d", j); + HDsnprintf(objname, sizeof(objname), "Group #%d", j); if ((gid_sub2 = H5Gcreate2(gid_sub, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; for (k = 0; k < NUM_DATASETS; k++) { - HDsprintf(objname, "Dataset #%d", k); + HDsnprintf(objname, sizeof(objname), "Dataset #%d", k); /* add a dataset to the group */ if ((did = H5Dcreate2(gid_sub2, objname, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, @@ -8222,12 +8222,12 @@ test_copy_group_wide_loop(hid_t fcpl_src, hid_t fcpl_dst, hid_t src_fapl, hid_t /* create wide sub-group hierarchy, with multiple links to higher groups */ for (u = 0; u < NUM_WIDE_LOOP_GROUPS; u++) { - HDsprintf(objname, "%s-%u", NAME_GROUP_SUB, u); + HDsnprintf(objname, sizeof(objname), "%s-%u", NAME_GROUP_SUB, u); if ((gid_sub = H5Gcreate2(gid, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; for (v = 0; v < NUM_WIDE_LOOP_GROUPS; v++) { - HDsprintf(objname, "%s-%u", NAME_GROUP_SUB_SUB2, v); + HDsnprintf(objname, sizeof(objname), "%s-%u", NAME_GROUP_SUB_SUB2, v); if ((gid_sub2 = H5Gcreate2(gid_sub, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR; diff --git a/test/objcopy_ref.c b/test/objcopy_ref.c index adc1a84..d10adf6 100644 --- a/test/objcopy_ref.c +++ b/test/objcopy_ref.c @@ -509,7 +509,7 @@ test_copy_attach_attributes(hid_t loc_id, hid_t type_id) goto done; for (u = 0; u < num_attributes_g; u++) { - HDsprintf(attr_name, "%u attr", u); + HDsnprintf(attr_name, sizeof(attr_name), "%u attr", u); /* Set attribute data */ attr_data[0] = (int)(100 * u); diff --git a/test/ohdr.c b/test/ohdr.c index 6b31334..dc0497f 100644 --- a/test/ohdr.c +++ b/test/ohdr.c @@ -1883,7 +1883,7 @@ main(void) /* Display info about testing */ low_string = h5_get_version_string(low); high_string = h5_get_version_string(high); - HDsprintf(msg, "Using file format version: (%s, %s)", low_string, high_string); + HDsnprintf(msg, sizeof(msg), "Using file format version: (%s, %s)", low_string, high_string); HDputs(msg); /* test on object continuation block */ diff --git a/test/stab.c b/test/stab.c index d08ebca..b4c92a4 100644 --- a/test/stab.c +++ b/test/stab.c @@ -219,8 +219,9 @@ test_long(hid_t fcpl, hid_t fapl, hbool_t new_format) for (i = 0; i < LONG_NAME_LEN; i++) name1[i] = (char)('A' + i % 26); name1[LONG_NAME_LEN - 1] = '\0'; - name2 = (char *)HDmalloc((size_t)((2 * LONG_NAME_LEN) + 2)); - HDsprintf(name2, "%s/%s", name1, name1); + size_t name2Len = (2 * LONG_NAME_LEN) + 2; + name2 = (char *)HDmalloc(name2Len); + HDsnprintf(name2, name2Len, "%s/%s", name1, name1); /* Create groups */ if ((g1 = H5Gcreate2(fid, name1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) @@ -310,7 +311,7 @@ test_large(hid_t fcpl, hid_t fapl, hbool_t new_format) if (H5G__has_stab_test(cwg) != FALSE) TEST_ERROR; for (i = 0; i < LARGE_NOBJS; i++) { - HDsprintf(name, "%05d%05d", (HDrandom() % 100000), i); + HDsnprintf(name, sizeof(name), "%05d%05d", (HDrandom() % 100000), i); if ((dir = H5Gcreate2(cwg, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; if (H5Gclose(dir) < 0) @@ -452,7 +453,7 @@ lifecycle(hid_t fcpl, hid_t fapl2) TEST_ERROR; /* Create first "bottom" group */ - HDsprintf(objname, LIFECYCLE_BOTTOM_GROUP, (unsigned)0); + HDsnprintf(objname, sizeof(objname), LIFECYCLE_BOTTOM_GROUP, (unsigned)0); if ((gid2 = H5Gcreate2(gid, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; @@ -475,7 +476,7 @@ lifecycle(hid_t fcpl, hid_t fapl2) /* Create several more bottom groups, to push the top group almost to a symbol table */ /* (Start counting at '1', since we've already created one bottom group */ for (u = 1; u < LIFECYCLE_MAX_COMPACT; u++) { - HDsprintf(objname, LIFECYCLE_BOTTOM_GROUP, u); + HDsnprintf(objname, sizeof(objname), LIFECYCLE_BOTTOM_GROUP, u); if ((gid2 = H5Gcreate2(gid, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; @@ -511,7 +512,7 @@ lifecycle(hid_t fcpl, hid_t fapl2) TEST_ERROR; /* Create one more "bottom" group, which should push top group into using a symbol table */ - HDsprintf(objname, LIFECYCLE_BOTTOM_GROUP, u); + HDsnprintf(objname, sizeof(objname), LIFECYCLE_BOTTOM_GROUP, u); if ((gid2 = H5Gcreate2(gid, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; @@ -545,7 +546,7 @@ lifecycle(hid_t fcpl, hid_t fapl2) /* Unlink objects from top group */ while (u >= LIFECYCLE_MIN_DENSE) { - HDsprintf(objname, LIFECYCLE_BOTTOM_GROUP, u); + HDsnprintf(objname, sizeof(objname), LIFECYCLE_BOTTOM_GROUP, u); if (H5Ldelete(gid, objname, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; @@ -562,7 +563,7 @@ lifecycle(hid_t fcpl, hid_t fapl2) TEST_ERROR; /* Unlink one more object from the group, which should transform back to using links */ - HDsprintf(objname, LIFECYCLE_BOTTOM_GROUP, u); + HDsnprintf(objname, sizeof(objname), LIFECYCLE_BOTTOM_GROUP, u); if (H5Ldelete(gid, objname, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; u--; @@ -576,11 +577,11 @@ lifecycle(hid_t fcpl, hid_t fapl2) TEST_ERROR; /* Unlink last two objects from top group */ - HDsprintf(objname, LIFECYCLE_BOTTOM_GROUP, u); + HDsnprintf(objname, sizeof(objname), LIFECYCLE_BOTTOM_GROUP, u); if (H5Ldelete(gid, objname, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; u--; - HDsprintf(objname, LIFECYCLE_BOTTOM_GROUP, u); + HDsnprintf(objname, sizeof(objname), LIFECYCLE_BOTTOM_GROUP, u); if (H5Ldelete(gid, objname, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; @@ -841,7 +842,7 @@ read_old(void) /* Create a bunch of objects in the group */ for (u = 0; u < READ_OLD_NGROUPS; u++) { - HDsprintf(objname, "Group %u", u); + HDsnprintf(objname, sizeof(objname), "Group %u", u); if ((gid2 = H5Gcreate2(gid, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; @@ -865,7 +866,7 @@ read_old(void) /* Delete new objects from old group */ for (u = 0; u < READ_OLD_NGROUPS; u++) { - HDsprintf(objname, "Group %u", u); + HDsnprintf(objname, sizeof(objname), "Group %u", u); if (H5Ldelete(gid, objname, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; } /* end for */ @@ -977,7 +978,7 @@ no_compact(hid_t fcpl, hid_t fapl2) TEST_ERROR; /* Create first "bottom" group */ - HDsprintf(objname, NO_COMPACT_BOTTOM_GROUP, (unsigned)0); + HDsnprintf(objname, sizeof(objname), NO_COMPACT_BOTTOM_GROUP, (unsigned)0); if ((gid2 = H5Gcreate2(gid, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; @@ -998,7 +999,7 @@ no_compact(hid_t fcpl, hid_t fapl2) TEST_ERROR; /* Unlink object from top group */ - HDsprintf(objname, NO_COMPACT_BOTTOM_GROUP, (unsigned)0); + HDsnprintf(objname, sizeof(objname), NO_COMPACT_BOTTOM_GROUP, (unsigned)0); if (H5Ldelete(gid, objname, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; diff --git a/test/swmr_common.c b/test/swmr_common.c index b359bc6..9063ddd 100644 --- a/test/swmr_common.c +++ b/test/swmr_common.c @@ -162,6 +162,9 @@ create_symbol_datatype(void) * Buffer for the created name. Must be pre-allocated. * Since the name is formulaic, this isn't considered an issue. * + * size_t name_buf_length + * The length in bytes of the name_buf buffer + * * unsigned level * The dataset's level * @@ -175,11 +178,11 @@ create_symbol_datatype(void) *------------------------------------------------------------------------- */ int -generate_name(char *name_buf, unsigned level, unsigned count) +generate_name(char *name_buf, size_t name_buf_length, unsigned level, unsigned count) { HDassert(name_buf); - HDsprintf(name_buf, "%u-%04u", level, count); + HDsnprintf(name_buf, name_buf_length, "%u-%04u", level, count); return 0; } /* end generate_name() */ @@ -206,7 +209,7 @@ generate_symbols(void) for (v = 0; v < symbol_count[u]; v++) { char name_buf[64]; - generate_name(name_buf, u, v); + generate_name(name_buf, sizeof(name_buf), u, v); symbol_info[u][v].name = HDstrdup(name_buf); symbol_info[u][v].dsid = -1; symbol_info[u][v].nrecords = 0; diff --git a/test/swmr_common.h b/test/swmr_common.h index d0d829d..5fcf923 100644 --- a/test/swmr_common.h +++ b/test/swmr_common.h @@ -66,10 +66,10 @@ extern "C" { H5TEST_DLL symbol_info_t *choose_dataset(void); H5TEST_DLL hid_t create_symbol_datatype(void); -H5TEST_DLL int generate_name(char *name_buf, unsigned level, unsigned count); -H5TEST_DLL int generate_symbols(void); -H5TEST_DLL int shutdown_symbols(void); -H5TEST_DLL int print_metadata_retries_info(hid_t fid); +H5TEST_DLL int generate_name(char *name_buf, size_t name_buf_length, unsigned level, unsigned count); +H5TEST_DLL int generate_symbols(void); +H5TEST_DLL int shutdown_symbols(void); +H5TEST_DLL int print_metadata_retries_info(hid_t fid); #ifdef __cplusplus } diff --git a/test/swmr_generator.c b/test/swmr_generator.c index 93cfa0f..51caa27 100644 --- a/test/swmr_generator.c +++ b/test/swmr_generator.c @@ -188,7 +188,7 @@ gen_skeleton(const char *filename, hbool_t verbose, hbool_t swmr_write, int comp hbool_t move_dataspace_message = FALSE; /* Whether to move the dataspace message out of object header chunk #0 */ - generate_name(name_buf, u, v); + generate_name(name_buf, sizeof(name_buf), u, v); if ((dsid = H5Dcreate2(fid, name_buf, tid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) return -1; diff --git a/test/tattr.c b/test/tattr.c index 2859f4c..d214719 100644 --- a/test/tattr.c +++ b/test/tattr.c @@ -2737,7 +2737,7 @@ test_attr_dense_rename(hid_t fcpl, hid_t fapl) CHECK(ret, FAIL, "H5Aclose"); /* Rename attribute */ - HDsprintf(new_attrname, "new attr %02u", u); + HDsnprintf(new_attrname, sizeof(new_attrname), "new attr %02u", u); /* Rename attribute */ ret = H5Arename_by_name(fid, DSET1_NAME, attrname, new_attrname, H5P_DEFAULT); @@ -9015,7 +9015,7 @@ test_attr_shared_rename(hid_t fcpl, hid_t fapl) VERIFY(is_dense, TRUE, "H5O__is_attr_dense_test"); /* Create new attribute name */ - HDsprintf(attrname2, "new attr %02u", u); + HDsnprintf(attrname2, sizeof(attrname2), "new attr %02u", u); /* Change second dataset's attribute's name */ ret = H5Arename_by_name(fid, DSET2_NAME, attrname, attrname2, H5P_DEFAULT); @@ -10126,7 +10126,7 @@ test_attr_bug2(hid_t fcpl, hid_t fapl) /* Create attributes on group */ for (i = 0; i < BUG2_NATTR; i++) { - HDsprintf(aname, "%03u", i); + HDsnprintf(aname, sizeof(aname), "%03u", i); aid = H5Acreate2(gid, aname, H5T_STD_I32LE, sid, H5P_DEFAULT, H5P_DEFAULT); CHECK(aid, FAIL, "H5Acreate2"); @@ -10136,7 +10136,7 @@ test_attr_bug2(hid_t fcpl, hid_t fapl) /* Delete every other attribute */ for (i = 1; i < BUG2_NATTR; i += 2) { - HDsprintf(aname, "%03u", i); + HDsnprintf(aname, sizeof(aname), "%03u", i); ret = H5Adelete(gid, aname); CHECK(ret, FAIL, "H5Adelete"); } @@ -10160,7 +10160,7 @@ test_attr_bug2(hid_t fcpl, hid_t fapl) /* Open an attribute in the middle */ i = (BUG2_NATTR / 4) * 2; - HDsprintf(aname, "%03u", i); + HDsnprintf(aname, sizeof(aname), "%03u", i); aid = H5Aopen(gid, aname, H5P_DEFAULT); CHECK(aid, FAIL, "H5Aopen"); @@ -10203,7 +10203,7 @@ test_attr_bug2(hid_t fcpl, hid_t fapl) /* Create attributes on group */ for (i = 0; i < BUG2_NATTR2; i++) { - HDsprintf(aname, "%03u", i); + HDsnprintf(aname, sizeof(aname), "%03u", i); aid = H5Acreate2(gid, aname, H5T_STD_I32LE, sid, H5P_DEFAULT, H5P_DEFAULT); CHECK(aid, FAIL, "H5Acreate2"); @@ -10213,7 +10213,7 @@ test_attr_bug2(hid_t fcpl, hid_t fapl) /* Delete every other attribute */ for (i = 0; i < BUG2_NATTR2; i++) { - HDsprintf(aname, "%03u", i); + HDsnprintf(aname, sizeof(aname), "%03u", i); ret = H5Adelete(gid, aname); CHECK(ret, FAIL, "H5Adelete"); } diff --git a/test/testmeta.c b/test/testmeta.c index a3b5160..a62977b 100644 --- a/test/testmeta.c +++ b/test/testmeta.c @@ -83,7 +83,7 @@ main(void) for (i = 0; i < NEXTARRAYS; i++) { /* Create dataset */ - HDsprintf(name, "/ExtArray%06d", i); + HDsnprintf(name, sizeof(name), "/ExtArray%06d", i); dataset_id = H5Dcreate2(file_id, name, H5T_NATIVE_FLOAT, dataspace_id, H5P_DEFAULT, prop_id, H5P_DEFAULT); @@ -108,7 +108,7 @@ main(void) floatval = (float)j; /* Create group to hold data arrays for this object */ - HDsprintf(name, "/DataArray/%06d", j); + HDsnprintf(name, sizeof(name), "/DataArray/%06d", j); group_id = H5Gcreate2(file_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if (group_id < 0) { HDfprintf(stderr, "Failed to create DataArray group.\n"); @@ -124,7 +124,7 @@ main(void) dataspace_id = H5Screate_simple(1, dims, maxdims); /* Create dataset */ - HDsprintf(name, "DataArray%06d", i); + HDsnprintf(name, sizeof(name), "DataArray%06d", i); dataset_id = H5Dcreate2(group_id, name, H5T_NATIVE_FLOAT, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if (dataset_id < 0) { @@ -170,7 +170,7 @@ main(void) /* Extend attribute arrays */ for (i = 0; i < NEXTARRAYS; i++) { /* Open extendable dataset */ - HDsprintf(name, "/ExtArray%06d", i); + HDsnprintf(name, sizeof(name), "/ExtArray%06d", i); dataset_id = H5Dopen2(file_id, name, H5P_DEFAULT); if (dataset_id < 0) { HDfprintf(stderr, "Failed to open ExtArray dataset.\n"); diff --git a/test/tfile.c b/test/tfile.c index 717eb91..caf9c62 100644 --- a/test/tfile.c +++ b/test/tfile.c @@ -1111,14 +1111,14 @@ test_get_obj_ids(void) /* creates NGROUPS groups under the root group */ for (m = 0; m < NGROUPS; m++) { - HDsprintf(gname, "group%d", m); + HDsnprintf(gname, sizeof(gname), "group%d", m); gid[m] = H5Gcreate2(fid, gname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(gid[m], FAIL, "H5Gcreate2"); } /* create NDSETS datasets under the root group */ for (n = 0; n < NDSETS; n++) { - HDsprintf(dname, "dataset%d", n); + HDsnprintf(dname, sizeof(dname), "dataset%d", n); dset[n] = H5Dcreate2(fid, dname, H5T_NATIVE_INT, filespace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(dset[n], FAIL, "H5Dcreate2"); } @@ -1178,7 +1178,7 @@ test_get_obj_ids(void) /* Open NDSETS datasets under the root group */ for (n = 0; n < NDSETS; n++) { - HDsprintf(dname, "dataset%d", n); + HDsnprintf(dname, sizeof(dname), "dataset%d", n); dset[n] = H5Dopen2(fid, dname, H5P_DEFAULT); CHECK(dset[n], FAIL, "H5Dcreate2"); } @@ -4473,7 +4473,7 @@ test_file_freespace(const char *env_h5_drvr) /* Create datasets in file */ for (u = 0; u < 10; u++) { - HDsprintf(name, "Dataset %u", u); + HDsnprintf(name, sizeof(name), "Dataset %u", u); dset = H5Dcreate2(file, name, H5T_STD_U32LE, dspace, H5P_DEFAULT, dcpl, H5P_DEFAULT); CHECK(dset, FAIL, "H5Dcreate2"); @@ -4496,7 +4496,7 @@ test_file_freespace(const char *env_h5_drvr) /* Delete datasets in file */ for (k = 9; k >= 0; k--) { - HDsprintf(name, "Dataset %u", (unsigned)k); + HDsnprintf(name, sizeof(name), "Dataset %u", (unsigned)k); ret = H5Ldelete(file, name, H5P_DEFAULT); CHECK(ret, FAIL, "H5Ldelete"); } /* end for */ @@ -4624,7 +4624,7 @@ test_sects_freespace(const char *env_h5_drvr, hbool_t new_format) /* Create datasets in file */ for (u = 0; u < 10; u++) { - HDsprintf(name, "Dataset %u", u); + HDsnprintf(name, sizeof(name), "Dataset %u", u); dset = H5Dcreate2(file, name, H5T_STD_U32LE, dspace, H5P_DEFAULT, dcpl, H5P_DEFAULT); CHECK(dset, FAIL, "H5Dcreate2"); @@ -4642,7 +4642,7 @@ test_sects_freespace(const char *env_h5_drvr, hbool_t new_format) /* Delete odd-numbered datasets in file */ for (u = 0; u < 10; u++) { - HDsprintf(name, "Dataset %u", u); + HDsnprintf(name, sizeof(name), "Dataset %u", u); if (u % 2) { ret = H5Ldelete(file, name, H5P_DEFAULT); CHECK(ret, FAIL, "H5Ldelete"); @@ -7590,7 +7590,7 @@ test_incr_filesize(void) /* Create datasets in file */ for (u = 0; u < 10; u++) { - HDsprintf(name, "Dataset %u", u); + HDsnprintf(name, sizeof(name), "Dataset %u", u); dset = H5Dcreate2(fid, name, H5T_STD_U32LE, dspace, H5P_DEFAULT, dcpl, H5P_DEFAULT); CHECK(dset, FAIL, "H5Dcreate2"); diff --git a/test/th5o.c b/test/th5o.c index 9504f7a..4ffcbef 100644 --- a/test/th5o.c +++ b/test/th5o.c @@ -1738,7 +1738,7 @@ test_h5o_getinfo_visit(void) /* Attach 10 attributes to "group1" */ for (j = 0; j < 10; j++) { /* Create the attribute name */ - HDsprintf(attrname, "attr%u", j); + HDsnprintf(attrname, sizeof(attrname), "attr%u", j); /* Create the attribute */ aid = H5Acreate2(gid1, attrname, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT); CHECK(aid, FAIL, "H5Acreate2"); diff --git a/test/titerate.c b/test/titerate.c index 1d87343..5796f11 100644 --- a/test/titerate.c +++ b/test/titerate.c @@ -156,7 +156,7 @@ test_iter_group(hid_t fapl, hbool_t new_format) CHECK(filespace, FAIL, "H5Screate"); for (i = 0; i < NDATASETS; i++) { - HDsprintf(name, "Dataset %d", i); + HDsnprintf(name, sizeof(name), "Dataset %d", i); dataset = H5Dcreate2(file, name, datatype, filespace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dcreate2"); @@ -436,7 +436,7 @@ test_iter_attr(hid_t fapl, hbool_t new_format) CHECK(dataset, FAIL, "H5Dcreate2"); for (i = 0; i < NATTR; i++) { - HDsprintf(name, "Attribute %02d", i); + HDsnprintf(name, sizeof(name), "Attribute %02d", i); attribute = H5Acreate2(dataset, name, H5T_NATIVE_INT, filespace, H5P_DEFAULT, H5P_DEFAULT); CHECK(attribute, FAIL, "H5Acreate2"); @@ -649,7 +649,7 @@ test_iter_group_large(hid_t fapl) /* Create a bunch of groups */ for (i = 0; i < ITER_NGROUPS; i++) { - HDsprintf(gname, "Group_%d", i); + HDsnprintf(gname, sizeof(gname), "Group_%d", i); /* Add the name to the list of objects in the root group */ HDstrcpy(names[i].name, gname); @@ -766,7 +766,7 @@ test_grp_memb_funcs(hid_t fapl) CHECK(filespace, FAIL, "H5Screate"); for (i = 0; i < NDATASETS; i++) { - HDsprintf(name, "Dataset %d", i); + HDsnprintf(name, sizeof(name), "Dataset %d", i); dataset = H5Dcreate2(file, name, datatype, filespace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dcreate2"); diff --git a/test/unlink.c b/test/unlink.c index 2527e94..265c497 100644 --- a/test/unlink.c +++ b/test/unlink.c @@ -179,12 +179,12 @@ test_many(hid_t file) /* Create a bunch of names and unlink them in order */ TESTING("forward unlink"); for (i = 0; i < how_many; i++) { - HDsprintf(name, "obj_%05d", i); + HDsnprintf(name, sizeof(name), "obj_%05d", i); if (H5Lcreate_hard(work, "/test_many_foo", H5L_SAME_LOC, name, H5P_DEFAULT, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; } /* end for */ for (i = 0; i < how_many; i++) { - HDsprintf(name, "obj_%05d", i); + HDsnprintf(name, sizeof(name), "obj_%05d", i); if (H5Ldelete(work, name, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; } /* end for */ @@ -193,12 +193,12 @@ test_many(hid_t file) /* Create a bunch of names and unlink them in reverse order */ TESTING("backward unlink"); for (i = 0; i < how_many; i++) { - HDsprintf(name, "obj_%05d", i); + HDsnprintf(name, sizeof(name), "obj_%05d", i); if (H5Lcreate_hard(work, "/test_many_foo", H5L_SAME_LOC, name, H5P_DEFAULT, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; } /* end for */ for (i = (how_many - 1); i >= 0; --i) { - HDsprintf(name, "obj_%05d", i); + HDsnprintf(name, sizeof(name), "obj_%05d", i); if (H5Ldelete(work, name, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; } /* end for */ @@ -207,15 +207,15 @@ test_many(hid_t file) /* Create a bunch of names and unlink them from both directions */ TESTING("inward unlink"); for (i = 0; i < how_many; i++) { - HDsprintf(name, "obj_%05d", i); + HDsnprintf(name, sizeof(name), "obj_%05d", i); if (H5Lcreate_hard(work, "/test_many_foo", H5L_SAME_LOC, name, H5P_DEFAULT, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; } /* end for */ for (i = 0; i < how_many; i++) { if (i % 2) - HDsprintf(name, "obj_%05d", how_many - (1 + i / 2)); + HDsnprintf(name, sizeof(name), "obj_%05d", how_many - (1 + i / 2)); else - HDsprintf(name, "obj_%05d", i / 2); + HDsnprintf(name, sizeof(name), "obj_%05d", i / 2); if (H5Ldelete(work, name, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; } /* end for */ @@ -224,15 +224,15 @@ test_many(hid_t file) /* Create a bunch of names and unlink them from the midle */ TESTING("outward unlink"); for (i = 0; i < how_many; i++) { - HDsprintf(name, "obj_%05d", i); + HDsnprintf(name, sizeof(name), "obj_%05d", i); if (H5Lcreate_hard(work, "/test_many_foo", H5L_SAME_LOC, name, H5P_DEFAULT, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; } /* end for */ for (i = (how_many - 1); i >= 0; --i) { if (i % 2) - HDsprintf(name, "obj_%05d", how_many - (1 + i / 2)); + HDsnprintf(name, sizeof(name), "obj_%05d", how_many - (1 + i / 2)); else - HDsprintf(name, "obj_%05d", i / 2); + HDsnprintf(name, sizeof(name), "obj_%05d", i / 2); if (H5Ldelete(work, name, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; } /* end for */ @@ -938,7 +938,7 @@ test_filespace(hid_t fapl) /* Alternate adding attributes to each one */ for (u = 0; u < FILESPACE_NATTR; u++) { /* Set the name of the attribute to create */ - HDsprintf(objname, "%s %u", ATTRNAME, u); + HDsnprintf(objname, sizeof(objname), "%s %u", ATTRNAME, u); /* Create an attribute on the first dataset */ if ((attr = H5Acreate2(dataset, objname, H5T_NATIVE_INT, attr_space, H5P_DEFAULT, H5P_DEFAULT)) < 0) @@ -1070,7 +1070,7 @@ test_filespace(hid_t fapl) /* Create a many groups to remove */ for (u = 0; u < UNLINK_NGROUPS; u++) { - HDsprintf(objname, "%s %u", GROUPNAME, u); + HDsnprintf(objname, sizeof(objname), "%s %u", GROUPNAME, u); if ((group = H5Gcreate2(file, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR; if (H5Gclose(group) < 0) @@ -1080,7 +1080,7 @@ test_filespace(hid_t fapl) /* Remove the all the groups */ /* (Remove them in reverse order just to make file size calculation easier -QAK) */ for (u = UNLINK_NGROUPS; u > 0; u--) { - HDsprintf(objname, "%s %u", GROUPNAME, (u - 1)); + HDsnprintf(objname, sizeof(objname), "%s %u", GROUPNAME, (u - 1)); if (H5Ldelete(file, objname, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; } /* end for */ @@ -1148,21 +1148,21 @@ test_filespace(hid_t fapl) /* Create a complex group hierarchy to remove */ for (u = 0; u < FILESPACE_TOP_GROUPS; u++) { /* Create group */ - HDsprintf(objname, "%s %u", GROUPNAME, u); + HDsnprintf(objname, sizeof(objname), "%s %u", GROUPNAME, u); if ((group = H5Gcreate2(file, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR; /* Create nested groups inside top groups */ for (v = 0; v < FILESPACE_NESTED_GROUPS; v++) { /* Create group */ - HDsprintf(objname, "%s %u", GROUP2NAME, v); + HDsnprintf(objname, sizeof(objname), "%s %u", GROUP2NAME, v); if ((group2 = H5Gcreate2(group, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR; /* Create datasets inside nested groups */ for (w = 0; w < FILESPACE_NDATASETS; w++) { /* Create & close a dataset */ - HDsprintf(objname, "%s %u", DATASETNAME, w); + HDsnprintf(objname, sizeof(objname), "%s %u", DATASETNAME, w); if ((dataset = H5Dcreate2(group2, objname, H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR; @@ -1184,21 +1184,21 @@ test_filespace(hid_t fapl) /* (Remove them in reverse order just to make file size calculation easier -QAK) */ for (u = FILESPACE_TOP_GROUPS; u > 0; u--) { /* Open group */ - HDsprintf(objname, "%s %u", GROUPNAME, (u - 1)); + HDsnprintf(objname, sizeof(objname), "%s %u", GROUPNAME, (u - 1)); if ((group = H5Gopen2(file, objname, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR; /* Open nested groups inside top groups */ for (v = 0; v < FILESPACE_NESTED_GROUPS; v++) { /* Create group */ - HDsprintf(objname, "%s %u", GROUP2NAME, v); + HDsnprintf(objname, sizeof(objname), "%s %u", GROUP2NAME, v); if ((group2 = H5Gopen2(group, objname, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR; /* Remove datasets inside nested groups */ for (w = 0; w < FILESPACE_NDATASETS; w++) { /* Remove dataset */ - HDsprintf(objname, "%s %u", DATASETNAME, w); + HDsnprintf(objname, sizeof(objname), "%s %u", DATASETNAME, w); if (H5Ldelete(group2, objname, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; } /* end for */ @@ -1208,7 +1208,7 @@ test_filespace(hid_t fapl) FAIL_STACK_ERROR; /* Remove nested group */ - HDsprintf(objname, "%s %u", GROUP2NAME, v); + HDsnprintf(objname, sizeof(objname), "%s %u", GROUP2NAME, v); if (H5Ldelete(group, objname, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; } /* end for */ @@ -1218,7 +1218,7 @@ test_filespace(hid_t fapl) FAIL_STACK_ERROR; /* Remove top group */ - HDsprintf(objname, "%s %u", GROUPNAME, (u - 1)); + HDsnprintf(objname, sizeof(objname), "%s %u", GROUPNAME, (u - 1)); if (H5Ldelete(file, objname, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; } /* end for */ @@ -1502,7 +1502,7 @@ test_create_unlink(const char *msg, hid_t fapl) /* Create a many groups to remove */ for (u = 0; u < UNLINK_NGROUPS; u++) { - HDsprintf(groupname, "%s %u", GROUPNAME, u); + HDsnprintf(groupname, sizeof(groupname), "%s %u", GROUPNAME, u); if ((group = H5Gcreate2(file, groupname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { H5_FAILED(); HDprintf("group %s creation failed\n", groupname); @@ -1517,7 +1517,7 @@ test_create_unlink(const char *msg, hid_t fapl) /* Remove the all the groups */ for (u = 0; u < UNLINK_NGROUPS; u++) { - HDsprintf(groupname, "%s %u", GROUPNAME, u); + HDsnprintf(groupname, sizeof(groupname), "%s %u", GROUPNAME, u); if (H5Ldelete(file, groupname, H5P_DEFAULT) < 0) { H5_FAILED(); HDprintf("Unlinking group %s failed\n", groupname); @@ -1765,7 +1765,7 @@ test_unlink_rightleaf(hid_t fid) /* Create all the groups */ for (n = 0; n < ngroups; n++) { - HDsprintf(name, "Zone%d", n + 1); + HDsnprintf(name, sizeof(name), "Zone%d", n + 1); if ((gids[n] = H5Gcreate2(rootid, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; } /* end for */ @@ -1774,7 +1774,7 @@ test_unlink_rightleaf(hid_t fid) for (n = 0; n < ngroups; n++) { if (delete_node(rootid, gids[n]) < 0) TEST_ERROR; - HDsprintf(name, "Zone%d", n + 1); + HDsnprintf(name, sizeof(name), "Zone%d", n + 1); if ((gids[n] = H5Gcreate2(rootid, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; } /* end for */ @@ -1854,7 +1854,7 @@ test_unlink_rightnode(hid_t fid) /* Create all the groups */ for (n = 0; n < ngroups; n++) { - HDsprintf(name, "ZoneB%d", n + 1); + HDsnprintf(name, sizeof(name), "ZoneB%d", n + 1); if ((gids[n] = H5Gcreate2(rootid, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR; } /* end for */ @@ -1946,7 +1946,7 @@ test_unlink_middlenode(hid_t fid) /* Create all the groups */ for (n = 0; n < ngroups; n++) { - HDsprintf(name, "ZoneC%d", n + 1); + HDsnprintf(name, sizeof(name), "ZoneC%d", n + 1); if ((gids[n] = H5Gcreate2(rootid, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR; } /* end for */ @@ -2676,7 +2676,7 @@ test_full_group_compact(hid_t fapl) /* Create several objects to link to */ for (u = 0; u < FULL_GROUP_NUM_KEEP; u++) { - HDsprintf(objname, "keep %u\n", u); + HDsnprintf(objname, sizeof(objname), "keep %u\n", u); if ((gid2 = H5Gcreate2(gid, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR; if (H5Gclose(gid2) < 0) @@ -2713,15 +2713,15 @@ test_full_group_compact(hid_t fapl) /* Create hard links to objects in group to keep */ for (u = 0; u < FULL_GROUP_NUM_KEEP; u++) { - HDsprintf(objname, "/keep/keep %u\n", u); - HDsprintf(objname2, "keep %u\n", u); + HDsnprintf(objname, sizeof(objname), "/keep/keep %u\n", u); + HDsnprintf(objname2, sizeof(objname2), "keep %u\n", u); if (H5Lcreate_hard(file_id, objname, gid, objname2, H5P_DEFAULT, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; } /* end for */ /* Create several objects to delete */ for (u = 0; u < FULL_GROUP_NUM_DELETE_COMPACT; u++) { - HDsprintf(objname, "delete %u\n", u); + HDsnprintf(objname, sizeof(objname), "delete %u\n", u); if ((gid2 = H5Gcreate2(gid, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR; if (H5Gclose(gid2) < 0) @@ -2742,7 +2742,7 @@ test_full_group_compact(hid_t fapl) /* Check reference count on objects to keep */ for (u = 0; u < FULL_GROUP_NUM_KEEP; u++) { - HDsprintf(objname, "/keep/keep %u\n", u); + HDsnprintf(objname, sizeof(objname), "/keep/keep %u\n", u); if (H5Oget_info_by_name3(file_id, objname, &oi, H5O_INFO_BASIC, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; if (oi.rc != 2) @@ -2763,7 +2763,7 @@ test_full_group_compact(hid_t fapl) /* Check reference count on objects to keep */ for (u = 0; u < FULL_GROUP_NUM_KEEP; u++) { - HDsprintf(objname, "/keep/keep %u\n", u); + HDsnprintf(objname, sizeof(objname), "/keep/keep %u\n", u); if (H5Oget_info_by_name3(file_id, objname, &oi, H5O_INFO_BASIC, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; if (oi.rc != 1) @@ -2838,7 +2838,7 @@ test_full_group_dense(hid_t fapl) /* Create several objects to link to */ for (u = 0; u < FULL_GROUP_NUM_KEEP; u++) { - HDsprintf(objname, "keep %u\n", u); + HDsnprintf(objname, sizeof(objname), "keep %u\n", u); if ((gid2 = H5Gcreate2(gid, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR; if (H5Gclose(gid2) < 0) @@ -2890,15 +2890,15 @@ test_full_group_dense(hid_t fapl) /* Create hard links to objects in group to keep */ for (u = 0; u < FULL_GROUP_NUM_KEEP; u++) { - HDsprintf(objname, "/keep/keep %u\n", u); - HDsprintf(objname2, "keep %u\n", u); + HDsnprintf(objname, sizeof(objname), "/keep/keep %u\n", u); + HDsnprintf(objname2, sizeof(objname2), "keep %u\n", u); if (H5Lcreate_hard(file_id, objname, gid, objname2, H5P_DEFAULT, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; } /* end for */ /* Create several objects to delete */ for (u = 0; u < FULL_GROUP_NUM_DELETE_DENSE; u++) { - HDsprintf(objname, "delete %u\n", u); + HDsnprintf(objname, sizeof(objname), "delete %u\n", u); if ((gid2 = H5Gcreate2(gid, objname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR; if (H5Gclose(gid2) < 0) @@ -2919,7 +2919,7 @@ test_full_group_dense(hid_t fapl) /* Check reference count on objects to keep */ for (u = 0; u < FULL_GROUP_NUM_KEEP; u++) { - HDsprintf(objname, "/keep/keep %u\n", u); + HDsnprintf(objname, sizeof(objname), "/keep/keep %u\n", u); if (H5Oget_info_by_name3(file_id, objname, &oi, H5O_INFO_BASIC, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; if (oi.rc != 2) @@ -2940,7 +2940,7 @@ test_full_group_dense(hid_t fapl) /* Check reference count on objects to keep */ for (u = 0; u < FULL_GROUP_NUM_KEEP; u++) { - HDsprintf(objname, "/keep/keep %u\n", u); + HDsnprintf(objname, sizeof(objname), "/keep/keep %u\n", u); if (H5Oget_info_by_name3(file_id, objname, &oi, H5O_INFO_BASIC, H5P_DEFAULT) < 0) FAIL_STACK_ERROR; if (oi.rc != 1) diff --git a/test/vfd.c b/test/vfd.c index d6f6d61..b4fc742 100644 --- a/test/vfd.c +++ b/test/vfd.c @@ -1538,19 +1538,19 @@ test_multi(void) memb_map[H5FD_MEM_BTREE] = H5FD_MEM_BTREE; memb_map[H5FD_MEM_GHEAP] = H5FD_MEM_GHEAP; - HDsprintf(sv[H5FD_MEM_SUPER], "%%s-%c.h5", 's'); + HDsnprintf(sv[H5FD_MEM_SUPER], 32, "%%s-%c.h5", 's'); memb_name[H5FD_MEM_SUPER] = sv[H5FD_MEM_SUPER]; memb_addr[H5FD_MEM_SUPER] = 0; - HDsprintf(sv[H5FD_MEM_BTREE], "%%s-%c.h5", 'b'); + HDsnprintf(sv[H5FD_MEM_BTREE], 32, "%%s-%c.h5", 'b'); memb_name[H5FD_MEM_BTREE] = sv[H5FD_MEM_BTREE]; memb_addr[H5FD_MEM_BTREE] = HADDR_MAX / 4; - HDsprintf(sv[H5FD_MEM_DRAW], "%%s-%c.h5", 'r'); + HDsnprintf(sv[H5FD_MEM_DRAW], 32, "%%s-%c.h5", 'r'); memb_name[H5FD_MEM_DRAW] = sv[H5FD_MEM_DRAW]; memb_addr[H5FD_MEM_DRAW] = HADDR_MAX / 2; - HDsprintf(sv[H5FD_MEM_GHEAP], "%%s-%c.h5", 'g'); + HDsnprintf(sv[H5FD_MEM_GHEAP], 32, "%%s-%c.h5", 'g'); memb_name[H5FD_MEM_GHEAP] = sv[H5FD_MEM_GHEAP]; memb_addr[H5FD_MEM_GHEAP] = (HADDR_MAX / 4) * 3; @@ -1787,12 +1787,12 @@ test_multi_compat(void) memb_map[H5FD_MEM_DRAW] = H5FD_MEM_DRAW; memb_fapl[H5FD_MEM_SUPER] = H5P_DEFAULT; - HDsprintf(sv[H5FD_MEM_SUPER], "%%s-%c.h5", 's'); + HDsnprintf(sv[H5FD_MEM_SUPER], 32, "%%s-%c.h5", 's'); memb_name[H5FD_MEM_SUPER] = sv[H5FD_MEM_SUPER]; memb_addr[H5FD_MEM_SUPER] = 0; memb_fapl[H5FD_MEM_DRAW] = H5P_DEFAULT; - HDsprintf(sv[H5FD_MEM_DRAW], "%%s-%c.h5", 'r'); + HDsnprintf(sv[H5FD_MEM_DRAW], 32, "%%s-%c.h5", 'r'); memb_name[H5FD_MEM_DRAW] = sv[H5FD_MEM_DRAW]; memb_addr[H5FD_MEM_DRAW] = HADDR_MAX / 2; @@ -1804,12 +1804,12 @@ test_multi_compat(void) /* Make copy for the data file in the build directory, to protect the * original file in the source directory */ - HDsprintf(filename_s, "%s-%c.h5", MULTI_COMPAT_BASENAME, 's'); - HDsprintf(newname_s, "%s-%c.h5", FILENAME[9], 's'); + HDsnprintf(filename_s, sizeof(filename_s), "%s-%c.h5", MULTI_COMPAT_BASENAME, 's'); + HDsnprintf(newname_s, sizeof(newname_s), "%s-%c.h5", FILENAME[9], 's'); h5_make_local_copy(filename_s, newname_s); - HDsprintf(filename_r, "%s-%c.h5", MULTI_COMPAT_BASENAME, 'r'); - HDsprintf(newname_r, "%s-%c.h5", FILENAME[9], 'r'); + HDsnprintf(filename_r, sizeof(filename_r), "%s-%c.h5", MULTI_COMPAT_BASENAME, 'r'); + HDsnprintf(newname_r, sizeof(newname_r), "%s-%c.h5", FILENAME[9], 'r'); h5_make_local_copy(filename_r, newname_r); /* Reopen the file for read only. Verify 1.8 library can open file diff --git a/testpar/t_2Gio.c b/testpar/t_2Gio.c index 63d6b69..ad8a15e 100644 --- a/testpar/t_2Gio.c +++ b/testpar/t_2Gio.c @@ -3704,9 +3704,10 @@ test_actual_io_mode(int selection_mode) /* Test values */ if (actual_chunk_opt_mode_expected != (H5D_mpio_actual_chunk_opt_mode_t)-1 && actual_io_mode_expected != (H5D_mpio_actual_io_mode_t)-1) { - HDsprintf(message, "Actual Chunk Opt Mode has the correct value for %s.\n", test_name); + HDsnprintf(message, sizeof(message), "Actual Chunk Opt Mode has the correct value for %s.\n", + test_name); VRFY((actual_chunk_opt_mode_write == actual_chunk_opt_mode_expected), message); - HDsprintf(message, "Actual IO Mode has the correct value for %s.\n", test_name); + HDsnprintf(message, sizeof(message), "Actual IO Mode has the correct value for %s.\n", test_name); VRFY((actual_io_mode_write == actual_io_mode_expected), message); } else { @@ -4100,10 +4101,12 @@ test_no_collective_cause_mode(int selection_mode) /* Test values */ HDmemset(message, 0, sizeof(message)); - HDsprintf(message, "Local cause of Broken Collective I/O has the correct value for %s.\n", test_name); + HDsnprintf(message, sizeof(message), + "Local cause of Broken Collective I/O has the correct value for %s.\n", test_name); VRFY((no_collective_cause_local_write == no_collective_cause_local_expected), message); HDmemset(message, 0, sizeof(message)); - HDsprintf(message, "Global cause of Broken Collective I/O has the correct value for %s.\n", test_name); + HDsnprintf(message, sizeof(message), + "Global cause of Broken Collective I/O has the correct value for %s.\n", test_name); VRFY((no_collective_cause_global_write == no_collective_cause_global_expected), message); /* Release some resources */ diff --git a/testpar/t_dset.c b/testpar/t_dset.c index eb11b32..f34cc1d 100644 --- a/testpar/t_dset.c +++ b/testpar/t_dset.c @@ -3262,9 +3262,10 @@ test_actual_io_mode(int selection_mode) /* Test values */ if (actual_chunk_opt_mode_expected != (H5D_mpio_actual_chunk_opt_mode_t)-1 && actual_io_mode_expected != (H5D_mpio_actual_io_mode_t)-1) { - HDsprintf(message, "Actual Chunk Opt Mode has the correct value for %s.\n", test_name); + HDsnprintf(message, sizeof(message), "Actual Chunk Opt Mode has the correct value for %s.\n", + test_name); VRFY((actual_chunk_opt_mode_write == actual_chunk_opt_mode_expected), message); - HDsprintf(message, "Actual IO Mode has the correct value for %s.\n", test_name); + HDsnprintf(message, sizeof(message), "Actual IO Mode has the correct value for %s.\n", test_name); VRFY((actual_io_mode_write == actual_io_mode_expected), message); } else { diff --git a/testpar/t_mdset.c b/testpar/t_mdset.c index 339ca33..54d75e6 100644 --- a/testpar/t_mdset.c +++ b/testpar/t_mdset.c @@ -183,7 +183,7 @@ multiple_dset_write(void) VRFY((ret >= 0), "set fill-value succeeded"); for (n = 0; n < ndatasets; n++) { - HDsprintf(dname, "dataset %d", n); + HDsnprintf(dname, sizeof(dname), "dataset %d", n); dataset = H5Dcreate2(iof, dname, H5T_NATIVE_DOUBLE, filespace, H5P_DEFAULT, dcpl, H5P_DEFAULT); VRFY((dataset > 0), dname); @@ -878,11 +878,11 @@ collective_group_write(void) /* creates ngroups groups under the root group, writes chunked * datasets in parallel. */ for (m = 0; m < ngroups; m++) { - HDsprintf(gname, "group%d", m); + HDsnprintf(gname, sizeof(gname), "group%d", m); gid = H5Gcreate2(fid, gname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); VRFY((gid > 0), gname); - HDsprintf(dname, "dataset%d", m); + HDsnprintf(dname, sizeof(dname), "dataset%d", m); did = H5Dcreate2(gid, dname, H5T_NATIVE_INT, filespace, H5P_DEFAULT, dcpl, H5P_DEFAULT); VRFY((did > 0), dname); @@ -979,12 +979,12 @@ group_dataset_read(hid_t fid, int mpi_rank, int m) VRFY((outdata != NULL), "HDmalloc succeeded for outdata"); /* open every group under root group. */ - HDsprintf(gname, "group%d", m); + HDsnprintf(gname, sizeof(gname), "group%d", m); gid = H5Gopen2(fid, gname, H5P_DEFAULT); VRFY((gid > 0), gname); /* check the data. */ - HDsprintf(dname, "dataset%d", m); + HDsnprintf(dname, sizeof(dname), "dataset%d", m); did = H5Dopen2(gid, dname, H5P_DEFAULT); VRFY((did > 0), dname); @@ -1080,7 +1080,7 @@ multiple_group_write(void) /* creates ngroups groups under the root group, writes datasets in * parallel. */ for (m = 0; m < ngroups; m++) { - HDsprintf(gname, "group%d", m); + HDsnprintf(gname, sizeof(gname), "group%d", m); gid = H5Gcreate2(fid, gname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); VRFY((gid > 0), gname); @@ -1136,7 +1136,7 @@ write_dataset(hid_t memspace, hid_t filespace, hid_t gid) VRFY((outme != NULL), "HDmalloc succeeded for outme"); for (n = 0; n < NDATASET; n++) { - HDsprintf(dname, "dataset%d", n); + HDsnprintf(dname, sizeof(dname), "dataset%d", n); did = H5Dcreate2(gid, dname, H5T_NATIVE_INT, filespace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); VRFY((did > 0), dname); @@ -1174,7 +1174,7 @@ create_group_recursive(hid_t memspace, hid_t filespace, hid_t gid, int counter) } #endif /* BARRIER_CHECKS */ - HDsprintf(gname, "%dth_child_group", counter + 1); + HDsnprintf(gname, sizeof(gname), "%dth_child_group", counter + 1); child_gid = H5Gcreate2(gid, gname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); VRFY((child_gid > 0), gname); @@ -1228,7 +1228,7 @@ multiple_group_read(void) /* open every group under root group. */ for (m = 0; m < ngroups; m++) { - HDsprintf(gname, "group%d", m); + HDsnprintf(gname, sizeof(gname), "group%d", m); gid = H5Gopen2(fid, gname, H5P_DEFAULT); VRFY((gid > 0), gname); @@ -1285,7 +1285,7 @@ read_dataset(hid_t memspace, hid_t filespace, hid_t gid) VRFY((outdata != NULL), "HDmalloc succeeded for outdata"); for (n = 0; n < NDATASET; n++) { - HDsprintf(dname, "dataset%d", n); + HDsnprintf(dname, sizeof(dname), "dataset%d", n); did = H5Dopen2(gid, dname, H5P_DEFAULT); VRFY((did > 0), dname); @@ -1336,7 +1336,7 @@ recursive_read_group(hid_t memspace, hid_t filespace, hid_t gid, int counter) nerrors += err_num; if (counter < GROUP_DEPTH) { - HDsprintf(gname, "%dth_child_group", counter + 1); + HDsnprintf(gname, sizeof(gname), "%dth_child_group", counter + 1); child_gid = H5Gopen2(gid, gname, H5P_DEFAULT); VRFY((child_gid > 0), gname); recursive_read_group(memspace, filespace, child_gid, counter + 1); @@ -1358,7 +1358,7 @@ write_attribute(hid_t obj_id, int this_type, int num) MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); if (this_type == is_group) { - HDsprintf(attr_name, "Group Attribute %d", num); + HDsnprintf(attr_name, sizeof(attr_name), "Group Attribute %d", num); sid = H5Screate(H5S_SCALAR); aid = H5Acreate2(obj_id, attr_name, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT); H5Awrite(aid, H5T_NATIVE_INT, &num); @@ -1366,7 +1366,7 @@ write_attribute(hid_t obj_id, int this_type, int num) H5Sclose(sid); } /* end if */ else if (this_type == is_dset) { - HDsprintf(attr_name, "Dataset Attribute %d", num); + HDsnprintf(attr_name, sizeof(attr_name), "Dataset Attribute %d", num); for (i = 0; i < 8; i++) attr_data[i] = i; sid = H5Screate_simple(dspace_rank, dspace_dims, NULL); @@ -1389,14 +1389,14 @@ read_attribute(hid_t obj_id, int this_type, int num) MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); if (this_type == is_group) { - HDsprintf(attr_name, "Group Attribute %d", num); + HDsnprintf(attr_name, sizeof(attr_name), "Group Attribute %d", num); aid = H5Aopen(obj_id, attr_name, H5P_DEFAULT); H5Aread(aid, H5T_NATIVE_INT, &in_num); vrfy_errors = dataset_vrfy(NULL, NULL, NULL, group_block, &in_num, &num); H5Aclose(aid); } else if (this_type == is_dset) { - HDsprintf(attr_name, "Dataset Attribute %d", num); + HDsnprintf(attr_name, sizeof(attr_name), "Dataset Attribute %d", num); for (i = 0; i < 8; i++) out_data[i] = i; aid = H5Aopen(obj_id, attr_name, H5P_DEFAULT); diff --git a/testpar/t_vfd.c b/testpar/t_vfd.c index 81e4983..ad296ad 100644 --- a/testpar/t_vfd.c +++ b/testpar/t_vfd.c @@ -571,17 +571,20 @@ vector_read_test_1(int file_name_id, int mpi_rank, int mpi_size, H5FD_mpio_xfer_ if (xfer_mode == H5FD_MPIO_INDEPENDENT) { - sprintf(test_title, "parallel vector read test 1 -- %s / independent", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector read test 1 -- %s / independent", + vfd_name); } else if (coll_opt_mode == H5FD_MPIO_INDIVIDUAL_IO) { - sprintf(test_title, "parallel vector read test 1 -- %s / col op / ind I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector read test 1 -- %s / col op / ind I/O", + vfd_name); } else { HDassert(coll_opt_mode == H5FD_MPIO_COLLECTIVE_IO); - sprintf(test_title, "parallel vector read test 1 -- %s / col op / col I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector read test 1 -- %s / col op / col I/O", + vfd_name); } TESTING(test_title); @@ -817,17 +820,20 @@ vector_read_test_2(int file_name_id, int mpi_rank, int mpi_size, H5FD_mpio_xfer_ if (xfer_mode == H5FD_MPIO_INDEPENDENT) { - sprintf(test_title, "parallel vector read test 2 -- %s / independent", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector read test 2 -- %s / independent", + vfd_name); } else if (coll_opt_mode == H5FD_MPIO_INDIVIDUAL_IO) { - sprintf(test_title, "parallel vector read test 2 -- %s / col op / ind I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector read test 2 -- %s / col op / ind I/O", + vfd_name); } else { HDassert(coll_opt_mode == H5FD_MPIO_COLLECTIVE_IO); - sprintf(test_title, "parallel vector read test 2 -- %s / col op / col I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector read test 2 -- %s / col op / col I/O", + vfd_name); } TESTING(test_title); @@ -1139,17 +1145,20 @@ vector_read_test_3(int file_name_id, int mpi_rank, int mpi_size, H5FD_mpio_xfer_ if (xfer_mode == H5FD_MPIO_INDEPENDENT) { - sprintf(test_title, "parallel vector read test 3 -- %s / independent", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector read test 3 -- %s / independent", + vfd_name); } else if (coll_opt_mode == H5FD_MPIO_INDIVIDUAL_IO) { - sprintf(test_title, "parallel vector read test 3 -- %s / col op / ind I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector read test 3 -- %s / col op / ind I/O", + vfd_name); } else { HDassert(coll_opt_mode == H5FD_MPIO_COLLECTIVE_IO); - sprintf(test_title, "parallel vector read test 3 -- %s / col op / col I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector read test 3 -- %s / col op / col I/O", + vfd_name); } TESTING(test_title); @@ -1508,17 +1517,20 @@ vector_read_test_4(int file_name_id, int mpi_rank, int mpi_size, H5FD_mpio_xfer_ if (xfer_mode == H5FD_MPIO_INDEPENDENT) { - sprintf(test_title, "parallel vector read test 4 -- %s / independent", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector read test 4 -- %s / independent", + vfd_name); } else if (coll_opt_mode == H5FD_MPIO_INDIVIDUAL_IO) { - sprintf(test_title, "parallel vector read test 4 -- %s / col op / ind I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector read test 4 -- %s / col op / ind I/O", + vfd_name); } else { HDassert(coll_opt_mode == H5FD_MPIO_COLLECTIVE_IO); - sprintf(test_title, "parallel vector read test 4 -- %s / col op / col I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector read test 4 -- %s / col op / col I/O", + vfd_name); } TESTING(test_title); @@ -1951,17 +1963,20 @@ vector_read_test_5(int file_name_id, int mpi_rank, int mpi_size, H5FD_mpio_xfer_ if (xfer_mode == H5FD_MPIO_INDEPENDENT) { - sprintf(test_title, "parallel vector read test 5 -- %s / independent", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector read test 5 -- %s / independent", + vfd_name); } else if (coll_opt_mode == H5FD_MPIO_INDIVIDUAL_IO) { - sprintf(test_title, "parallel vector read test 5 -- %s / col op / ind I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector read test 5 -- %s / col op / ind I/O", + vfd_name); } else { HDassert(coll_opt_mode == H5FD_MPIO_COLLECTIVE_IO); - sprintf(test_title, "parallel vector read test 5 -- %s / col op / col I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector read test 5 -- %s / col op / col I/O", + vfd_name); } TESTING(test_title); @@ -2204,17 +2219,20 @@ vector_write_test_1(int file_name_id, int mpi_rank, int mpi_size, H5FD_mpio_xfer if (xfer_mode == H5FD_MPIO_INDEPENDENT) { - sprintf(test_title, "parallel vector write test 1 -- %s / independent", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 1 -- %s / independent", + vfd_name); } else if (coll_opt_mode == H5FD_MPIO_INDIVIDUAL_IO) { - sprintf(test_title, "parallel vector write test 1 -- %s / col op / ind I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 1 -- %s / col op / ind I/O", + vfd_name); } else { HDassert(coll_opt_mode == H5FD_MPIO_COLLECTIVE_IO); - sprintf(test_title, "parallel vector write test 1 -- %s / col op / col I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 1 -- %s / col op / col I/O", + vfd_name); } TESTING(test_title); @@ -2403,17 +2421,20 @@ vector_write_test_2(int file_name_id, int mpi_rank, int mpi_size, H5FD_mpio_xfer if (xfer_mode == H5FD_MPIO_INDEPENDENT) { - sprintf(test_title, "parallel vector write test 2 -- %s / independent", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 2 -- %s / independent", + vfd_name); } else if (coll_opt_mode == H5FD_MPIO_INDIVIDUAL_IO) { - sprintf(test_title, "parallel vector write test 2 -- %s / col op / ind I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 2 -- %s / col op / ind I/O", + vfd_name); } else { HDassert(coll_opt_mode == H5FD_MPIO_COLLECTIVE_IO); - sprintf(test_title, "parallel vector write test 2 -- %s / col op / col I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 2 -- %s / col op / col I/O", + vfd_name); } TESTING(test_title); @@ -2668,17 +2689,20 @@ vector_write_test_3(int file_name_id, int mpi_rank, int mpi_size, H5FD_mpio_xfer if (xfer_mode == H5FD_MPIO_INDEPENDENT) { - sprintf(test_title, "parallel vector write test 3 -- %s / independent", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 3 -- %s / independent", + vfd_name); } else if (coll_opt_mode == H5FD_MPIO_INDIVIDUAL_IO) { - sprintf(test_title, "parallel vector write test 3 -- %s / col op / ind I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 3 -- %s / col op / ind I/O", + vfd_name); } else { HDassert(coll_opt_mode == H5FD_MPIO_COLLECTIVE_IO); - sprintf(test_title, "parallel vector write test 3 -- %s / col op / col I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 3 -- %s / col op / col I/O", + vfd_name); } TESTING(test_title); @@ -2950,17 +2974,20 @@ vector_write_test_4(int file_name_id, int mpi_rank, int mpi_size, H5FD_mpio_xfer if (xfer_mode == H5FD_MPIO_INDEPENDENT) { - sprintf(test_title, "parallel vector write test 4 -- %s / independent", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 4 -- %s / independent", + vfd_name); } else if (coll_opt_mode == H5FD_MPIO_INDIVIDUAL_IO) { - sprintf(test_title, "parallel vector write test 4 -- %s / col op / ind I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 4 -- %s / col op / ind I/O", + vfd_name); } else { HDassert(coll_opt_mode == H5FD_MPIO_COLLECTIVE_IO); - sprintf(test_title, "parallel vector write test 4 -- %s / col op / col I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 4 -- %s / col op / col I/O", + vfd_name); } TESTING(test_title); @@ -3269,17 +3296,20 @@ vector_write_test_5(int file_name_id, int mpi_rank, int mpi_size, H5FD_mpio_xfer if (xfer_mode == H5FD_MPIO_INDEPENDENT) { - sprintf(test_title, "parallel vector write test 5 -- %s / independent", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 5 -- %s / independent", + vfd_name); } else if (coll_opt_mode == H5FD_MPIO_INDIVIDUAL_IO) { - sprintf(test_title, "parallel vector write test 5 -- %s / col op / ind I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 5 -- %s / col op / ind I/O", + vfd_name); } else { HDassert(coll_opt_mode == H5FD_MPIO_COLLECTIVE_IO); - sprintf(test_title, "parallel vector write test 5 -- %s / col op / col I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 5 -- %s / col op / col I/O", + vfd_name); } TESTING(test_title); @@ -3701,17 +3731,20 @@ vector_write_test_6(int file_name_id, int mpi_rank, int mpi_size, H5FD_mpio_xfer if (xfer_mode == H5FD_MPIO_INDEPENDENT) { - sprintf(test_title, "parallel vector write test 6 -- %s / independent", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 6 -- %s / independent", + vfd_name); } else if (coll_opt_mode == H5FD_MPIO_INDIVIDUAL_IO) { - sprintf(test_title, "parallel vector write test 6 -- %s / col op / ind I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 6 -- %s / col op / ind I/O", + vfd_name); } else { HDassert(coll_opt_mode == H5FD_MPIO_COLLECTIVE_IO); - sprintf(test_title, "parallel vector write test 6 -- %s / col op / col I/O", vfd_name); + snprintf(test_title, sizeof(test_title), "parallel vector write test 6 -- %s / col op / col I/O", + vfd_name); } TESTING(test_title); diff --git a/tools/src/h5perf/sio_engine.c b/tools/src/h5perf/sio_engine.c index c12e1da..e113e82 100644 --- a/tools/src/h5perf/sio_engine.c +++ b/tools/src/h5perf/sio_engine.c @@ -522,7 +522,7 @@ do_write(results *res, file_descr *fd, parameters *parms, void *buffer) } /* end if */ } /* end if */ - HDsprintf(dname, "Dataset_%ld", (unsigned long)parms->num_bytes); + HDsnprintf(dname, sizeof(dname), "Dataset_%ld", (unsigned long)parms->num_bytes); h5ds_id = H5Dcreate2(fd->h5fd, dname, ELMT_H5_TYPE, h5dset_space_id, H5P_DEFAULT, h5dcpl, H5P_DEFAULT); @@ -851,7 +851,7 @@ do_read(results *res, file_descr *fd, parameters *parms, void *buffer) break; case HDF5: - HDsprintf(dname, "Dataset_%ld", (long)parms->num_bytes); + HDsnprintf(dname, sizeof(dname), "Dataset_%ld", (long)parms->num_bytes); h5ds_id = H5Dopen2(fd->h5fd, dname, H5P_DEFAULT); if (h5ds_id < 0) { HDfprintf(stderr, "HDF5 Dataset open failed\n"); @@ -1181,7 +1181,7 @@ set_vfd(parameters *param) return -1; for (mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; mt++) { memb_fapl[mt] = H5P_DEFAULT; - HDsprintf(sv->arr[mt], "%%s-%c.h5", multi_letters[mt]); + HDsnprintf(sv->arr[mt], 1024, "%%s-%c.h5", multi_letters[mt]); memb_name[mt] = sv->arr[mt]; memb_addr[mt] = (haddr_t)MAX(mt - 1, 0) * (HADDR_MAX / 10); } diff --git a/tools/src/h5repack/h5repack_copy.c b/tools/src/h5repack/h5repack_copy.c index c38a431..25df5c7 100644 --- a/tools/src/h5repack/h5repack_copy.c +++ b/tools/src/h5repack/h5repack_copy.c @@ -1531,7 +1531,7 @@ print_dataset_info(hid_t dcpl_id, char *objname, double ratio, int pr, pack_opt_ { unsigned level = cd_values[0]; - HDsprintf(temp, "(%d)", level); + HDsnprintf(temp, sizeof(temp), "(%d)", level); HDstrcat(strfilter, temp); } #endif @@ -1545,7 +1545,7 @@ print_dataset_info(hid_t dcpl_id, char *objname, double ratio, int pr, pack_opt_ unsigned options_mask = cd_values[0]; /* from dcpl, not filt*/ unsigned ppb = cd_values[1]; - HDsprintf(temp, "(%d,", ppb); + HDsnprintf(temp, sizeof(temp), "(%d,", ppb); HDstrcat(strfilter, temp); if (options_mask & H5_SZIP_EC_OPTION_MASK) HDstrcpy(temp, "EC) "); @@ -1588,7 +1588,7 @@ print_dataset_info(hid_t dcpl_id, char *objname, double ratio, int pr, pack_opt_ HDstrcpy(str, "dset "); HDstrcat(str, strfilter); - HDsprintf(temp, " (%.3f:1)", ratio); + HDsnprintf(temp, sizeof(temp), " (%.3f:1)", ratio); HDstrcat(str, temp); if (options->verbose == 2) HDprintf(FORMAT_OBJ_TIME, str, read_time, write_time, objname); diff --git a/tools/src/misc/h5repart.c b/tools/src/misc/h5repart.c index f4cef6a..078883d 100644 --- a/tools/src/misc/h5repart.c +++ b/tools/src/misc/h5repart.c @@ -242,7 +242,7 @@ main(int argc, char *argv[]) if (argno >= argc) usage(prog_name); src_gen_name = argv[argno++]; - HDsprintf(src_name, src_gen_name, src_membno); + HDsnprintf(src_name, NAMELEN, src_gen_name, src_membno); src_is_family = strcmp(src_name, src_gen_name); if ((src = HDopen(src_name, O_RDONLY)) < 0) { @@ -264,7 +264,7 @@ main(int argc, char *argv[]) if (argno >= argc) usage(prog_name); dst_gen_name = argv[argno++]; - HDsprintf(dst_name, dst_gen_name, dst_membno); + HDsnprintf(dst_name, NAMELEN, dst_gen_name, dst_membno); dst_is_family = HDstrcmp(dst_name, dst_gen_name); if ((dst = HDopen(dst_name, O_RDWR | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_RW)) < 0) { @@ -356,7 +356,7 @@ main(int argc, char *argv[]) dst_offset = dst_offset + (off_t)n; break; } - HDsprintf(src_name, src_gen_name, ++src_membno); + HDsnprintf(src_name, NAMELEN, src_gen_name, ++src_membno); if ((src = HDopen(src_name, O_RDONLY)) < 0 && ENOENT == errno) { dst_offset = dst_offset + (off_t)n; break; @@ -404,7 +404,7 @@ main(int argc, char *argv[]) } } HDclose(dst); - HDsprintf(dst_name, dst_gen_name, ++dst_membno); + HDsnprintf(dst_name, NAMELEN, dst_gen_name, ++dst_membno); if ((dst = HDopen(dst_name, O_RDWR | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_RW)) < 0) { HDperror(dst_name); HDexit(EXIT_FAILURE); diff --git a/tools/test/h5dump/h5dumpgentest.c b/tools/test/h5dump/h5dumpgentest.c index 339b563..949aa43 100644 --- a/tools/test/h5dump/h5dumpgentest.c +++ b/tools/test/h5dump/h5dumpgentest.c @@ -582,7 +582,7 @@ gent_attribute(void) dims[0] = 24; space = H5Screate_simple(1, dims, NULL); attr = H5Acreate2(root, "/attr1", H5T_STD_I8BE, space, H5P_DEFAULT, H5P_DEFAULT); - HDsprintf(buf, "attribute of root group"); + HDsnprintf(buf, sizeof(buf), "attribute of root group"); H5Awrite(attr, H5T_NATIVE_SCHAR, buf); H5Sclose(space); H5Aclose(attr); @@ -1382,7 +1382,7 @@ gent_all(void) dims[0] = 10; space = H5Screate_simple(1, dims, NULL); attr = H5Acreate2(group, "attr1", H5T_STD_I8BE, space, H5P_DEFAULT, H5P_DEFAULT); - HDsprintf(buf, "abcdefghi"); + HDsnprintf(buf, sizeof(buf), "abcdefghi"); H5Awrite(attr, H5T_NATIVE_SCHAR, buf); H5Sclose(space); H5Aclose(attr); @@ -1418,7 +1418,7 @@ gent_all(void) dims[0] = 27; space = H5Screate_simple(1, dims, NULL); attr = H5Acreate2(dataset, "attr1", H5T_STD_I8BE, space, H5P_DEFAULT, H5P_DEFAULT); - HDsprintf(buf, "1st attribute of dset1.1.1"); + HDsnprintf(buf, sizeof(buf), "1st attribute of dset1.1.1"); H5Awrite(attr, H5T_NATIVE_SCHAR, buf); H5Sclose(space); H5Aclose(attr); @@ -1426,7 +1426,7 @@ gent_all(void) dims[0] = 27; space = H5Screate_simple(1, dims, NULL); attr = H5Acreate2(dataset, "attr2", H5T_STD_I8BE, space, H5P_DEFAULT, H5P_DEFAULT); - HDsprintf(buf, "2nd attribute of dset1.1.1"); + HDsnprintf(buf, sizeof(buf), "2nd attribute of dset1.1.1"); H5Awrite(attr, H5T_NATIVE_SCHAR, buf); H5Sclose(space); H5Aclose(attr); @@ -1625,7 +1625,7 @@ gent_many(void) dims[0] = 10; space2 = H5Screate_simple(1, dims, NULL); attr = H5Acreate2(dataset, "attr1", H5T_STD_I8BE, space2, H5P_DEFAULT, H5P_DEFAULT); - HDsprintf(buf, "abcdefghi"); + HDsnprintf(buf, sizeof(buf), "abcdefghi"); H5Awrite(attr, H5T_NATIVE_CHAR, buf); H5Sclose(space2); H5Aclose(attr); @@ -1963,9 +1963,9 @@ gent_str2(void) dims[0] = 3; space2 = H5Screate_simple(1, dims, NULL); attr = H5Acreate2(dataset, "attr1", fxdlenstr2, space2, H5P_DEFAULT, H5P_DEFAULT); - HDsprintf(&(buf2[0 * LENSTR2]), "0123456789"); - HDsprintf(&(buf2[1 * LENSTR2]), "abcdefghij"); - HDsprintf(&(buf2[2 * LENSTR2]), "ABCDEFGHIJ"); + HDsnprintf(&(buf2[0 * LENSTR2]), LENSTR2, "0123456789"); + HDsnprintf(&(buf2[1 * LENSTR2]), LENSTR2, "abcdefghij"); + HDsnprintf(&(buf2[2 * LENSTR2]), LENSTR2, "ABCDEFGHIJ"); H5Awrite(attr, fxdlenstr2, buf2); H5Sclose(space2); H5Tclose(fxdlenstr2); @@ -1977,7 +1977,7 @@ gent_str2(void) for (i = 0; (hsize_t)i < sdim; i++) { start[0] = (hsize_t)i; - HDsprintf(buf, "This is row %1d of type H5T_STR_NULLTERM of", i); + HDsnprintf(buf, sizeof(buf), "This is row %1d of type H5T_STR_NULLTERM of", i); H5Tset_size(memtype, HDstrlen(buf) + 1); H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block); H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf); @@ -1990,7 +1990,7 @@ gent_str2(void) for (i = 0; (hsize_t)i < sdim; i++) { start[0] = (hsize_t)i; - HDsprintf(buf, "This is row %1d of type H5T_STR_NULLTERM of string array", i); + HDsnprintf(buf, sizeof(buf), "This is row %1d of type H5T_STR_NULLTERM of string array", i); H5Tset_size(memtype, HDstrlen(buf) + 1); H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block); H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf); @@ -2009,7 +2009,7 @@ gent_str2(void) for (i = 0; (hsize_t)i < sdim; i++) { start[0] = (hsize_t)i; - HDsprintf(buf, "This is row %1d of type H5T_STR_NULLPAD of", i); + HDsnprintf(buf, sizeof(buf), "This is row %1d of type H5T_STR_NULLPAD of", i); H5Tset_size(memtype, HDstrlen(buf) + 1); H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block); H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf); @@ -2022,7 +2022,7 @@ gent_str2(void) for (i = 0; (hsize_t)i < sdim; i++) { start[0] = (hsize_t)i; - HDsprintf(buf, "This is row %1d of type H5T_STR_NULLPAD of string array", i); + HDsnprintf(buf, sizeof(buf), "This is row %1d of type H5T_STR_NULLPAD of string array", i); H5Tset_size(memtype, HDstrlen(buf) + 1); H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block); H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf); @@ -2041,7 +2041,7 @@ gent_str2(void) for (i = 0; (hsize_t)i < sdim; i++) { start[0] = (hsize_t)i; - HDsprintf(buf, "This is row %1d of type H5T_STR_SPACEPAD of", i); + HDsnprintf(buf, sizeof(buf), "This is row %1d of type H5T_STR_SPACEPAD of", i); H5Tset_size(memtype, HDstrlen(buf) + 1); H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block); H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf); @@ -2054,7 +2054,7 @@ gent_str2(void) for (i = 0; (hsize_t)i < sdim; i++) { start[0] = (hsize_t)i; - HDsprintf(buf, "This is row %1d of type H5T_STR_SPACEPAD of string array", i); + HDsnprintf(buf, sizeof(buf), "This is row %1d of type H5T_STR_SPACEPAD of string array", i); H5Tset_size(memtype, HDstrlen(buf) + 1); H5Sselect_hyperslab(hyper_space, H5S_SELECT_SET, start, stride, count, block); H5Dwrite(dataset, memtype, mem_space, hyper_space, H5P_DEFAULT, buf); @@ -3923,7 +3923,7 @@ gent_large_objname(void) group = H5Gcreate2(fid, "this_is_a_large_group_name", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); for (i = 0; i < 50; ++i) { - HDsprintf(grp_name, "this_is_a_large_group_name%d", i); + HDsnprintf(grp_name, sizeof(grp_name), "this_is_a_large_group_name%d", i); group2 = H5Gcreate2(group, grp_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Gclose(group2); } diff --git a/tools/test/h5jam/h5jamgentest.c b/tools/test/h5jam/h5jamgentest.c index 5632cc0..16604b3 100644 --- a/tools/test/h5jam/h5jamgentest.c +++ b/tools/test/h5jam/h5jamgentest.c @@ -152,7 +152,7 @@ gent_ub(const char *filename, size_t ub_size, size_t ub_fill) goto error; if ((attr = H5Acreate2(group, "attr1", H5T_STD_I8BE, space, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; - if (HDsprintf(buf, "abcdefghi") < 0) + if (HDsnprintf(buf, sizeof(buf), "abcdefghi") < 0) goto error; if (H5Awrite(attr, H5T_NATIVE_SCHAR, buf) < 0) goto error; @@ -206,7 +206,7 @@ gent_ub(const char *filename, size_t ub_size, size_t ub_fill) goto error; if ((attr = H5Acreate2(dataset, "attr1", H5T_STD_I8BE, space, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; - if (HDsprintf(buf, "1st attribute of dset1.1.1") < 0) + if (HDsnprintf(buf, sizeof(buf), "1st attribute of dset1.1.1") < 0) goto error; if (H5Awrite(attr, H5T_NATIVE_SCHAR, buf) < 0) goto error; @@ -220,7 +220,7 @@ gent_ub(const char *filename, size_t ub_size, size_t ub_fill) goto error; if ((attr = H5Acreate2(dataset, "attr2", H5T_STD_I8BE, space, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; - if (HDsprintf(buf, "2nd attribute of dset1.1.1") < 0) + if (HDsnprintf(buf, sizeof(buf), "2nd attribute of dset1.1.1") < 0) goto error; if (H5Awrite(attr, H5T_NATIVE_SCHAR, buf) < 0) goto error; diff --git a/tools/test/h5repack/h5repacktst.c b/tools/test/h5repack/h5repacktst.c index 8b114e4..028939a 100644 --- a/tools/test/h5repack/h5repacktst.c +++ b/tools/test/h5repack/h5repacktst.c @@ -3157,7 +3157,7 @@ make_early(void) goto out; if ((tid = H5Tcopy(H5T_NATIVE_DOUBLE)) < 0) goto out; - HDsprintf(name, "%d", i); + HDsnprintf(name, sizeof(name), "%d", i); if ((H5Tcommit2(fid, name, tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; if (H5Tclose(tid) < 0) @@ -3181,7 +3181,7 @@ make_early(void) for (i = 0; i < iter; i++) { if ((tid = H5Tcopy(H5T_NATIVE_DOUBLE)) < 0) goto out; - HDsprintf(name, "%d", i); + HDsnprintf(name, sizeof(name), "%d", i); if ((H5Tcommit2(fid, name, tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; if (H5Tclose(tid) < 0) @@ -3240,7 +3240,7 @@ make_layout(hid_t loc_id) *------------------------------------------------------------------------- */ for (i = 0; i < 4; i++) { - HDsprintf(name, "dset%d", i + 1); + HDsnprintf(name, sizeof(name), "dset%d", i + 1); if (write_dset(loc_id, RANK, dims, name, H5T_NATIVE_INT, buf) < 0) goto error; } diff --git a/tools/test/h5stat/h5stat_gentest.c b/tools/test/h5stat/h5stat_gentest.c index c775d6a..4d21a43 100644 --- a/tools/test/h5stat/h5stat_gentest.c +++ b/tools/test/h5stat/h5stat_gentest.c @@ -88,7 +88,7 @@ gen_newgrat_file(const char *fname) /* Create NUM_GRPS groups in the root group */ for (i = 1; i <= NUM_GRPS; i++) { - HDsprintf(name, "%s%d", GROUP_NAME, i); + HDsnprintf(name, sizeof(name), "%s%d", GROUP_NAME, i); if ((gid = H5Gcreate2(fid, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; if (H5Gclose(gid) < 0) @@ -109,7 +109,7 @@ gen_newgrat_file(const char *fname) /* Create NUM_ATTRS for the dataset */ for (i = 1; i <= NUM_ATTRS; i++) { - HDsprintf(attrname, "%s%d", ATTR_NAME, i); + HDsnprintf(attrname, sizeof(attrname), "%s%d", ATTR_NAME, i); if ((attr_id = H5Acreate2(did, attrname, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; if (H5Aclose(attr_id) < 0) @@ -211,7 +211,7 @@ gen_threshold_file(const char *fname) /* Create 11 attributes for the dataset */ for (i = 1; i <= (THRES_NUM + 1); i++) { - HDsprintf(name, "%s%d", THRES_ATTR_NAME, i); + HDsnprintf(name, sizeof(name), "%s%d", THRES_ATTR_NAME, i); if ((attr_id = H5Acreate2(did, name, H5T_NATIVE_INT, sid1, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; if (H5Aclose(attr_id) < 0) @@ -240,7 +240,7 @@ gen_threshold_file(const char *fname) /* Create 10 attributes for the 2-D dataset */ for (i = 1; i <= THRES_NUM; i++) { - HDsprintf(name, "%s%d", THRES_ATTR_NAME, i); + HDsnprintf(name, sizeof(name), "%s%d", THRES_ATTR_NAME, i); if ((attr_id = H5Acreate2(did, name, H5T_NATIVE_INT, sid1, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; if (H5Aclose(attr_id) < 0) @@ -264,7 +264,7 @@ gen_threshold_file(const char *fname) /* Create 10 1-D datasets with non-zero dimension size for the group */ for (i = 1; i <= THRES_NUM; i++) { /* set up dataset name */ - HDsprintf(name, "%s%d", THRES_DSET_NAME, i); + HDsnprintf(name, sizeof(name), "%s%d", THRES_DSET_NAME, i); /* Create the dataset */ if ((did = H5Dcreate2(gid, name, H5T_NATIVE_UCHAR, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) @@ -286,7 +286,7 @@ gen_threshold_file(const char *fname) /* Create 25 attributes for the group */ for (i = 1; i <= THRES_NUM_25; i++) { /* Set up attribute name */ - HDsprintf(name, "%s%d", THRES_ATTR_GRP_NAME, i); + HDsnprintf(name, sizeof(name), "%s%d", THRES_ATTR_GRP_NAME, i); /* Create the attribute */ if ((attr_id = H5Acreate2(gid, name, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT)) < 0) @@ -308,7 +308,7 @@ gen_threshold_file(const char *fname) /* Create 9 1-D datasets with non-zero dimension size for the group */ for (i = 1; i < THRES_NUM; i++) { /* set up dataset name */ - HDsprintf(name, "%s%d", THRES_DSET_NAME, i); + HDsnprintf(name, sizeof(name), "%s%d", THRES_DSET_NAME, i); /* Create the dataset */ if ((did = H5Dcreate2(gid, name, H5T_NATIVE_UCHAR, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) diff --git a/tools/test/misc/h5perf_gentest.c b/tools/test/misc/h5perf_gentest.c index 248fd92..7589144 100644 --- a/tools/test/misc/h5perf_gentest.c +++ b/tools/test/misc/h5perf_gentest.c @@ -104,7 +104,7 @@ main(int argc, char *argv[]) } if (strlen(fname) <= 0) - HDsprintf(fname, FNAME); + HDsnprintf(fname, sizeof(fname), FNAME); create_perf_test_file(fname, ngrps, ndsets, nattrs, (hsize_t)nrows, (hsize_t)dim0, (hsize_t)chunk, vlen, z, l); @@ -324,7 +324,7 @@ create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsiz fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); add_attrs(fid, 0); - HDsprintf(name, "a cmp ds of %d rows", nrows); + HDsnprintf(name, sizeof(name), "a cmp ds of %d rows", nrows); did = H5Dcreate(fid, name, cmp_tid, sid_large, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Dwrite(did, cmp_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_comp_large); add_attrs(did, 0); @@ -344,7 +344,7 @@ create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsiz add_attrs(gid1, 0); for (i = 0; i < ngrps; i++) { /* create sub groups */ - HDsprintf(name, "g%02d", i); + HDsnprintf(name, sizeof(name), "g%02d", i); gid2 = H5Gcreate(gid1, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if (i < 10) add_attrs(gid2, 0); @@ -357,14 +357,14 @@ create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsiz add_attrs(gid1, 0); for (j = 0; j < ndsets; j += 12) { /* 1 add a null dataset */ - HDsprintf(name, "%05d null dataset", j); + HDsnprintf(name, sizeof(name), "%05d null dataset", j); did = H5Dcreate(gid1, name, H5T_STD_I32LE, sid_null, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if (!j) add_attrs(did, j); H5Dclose(did); /* 2 add scalar int point */ - HDsprintf(name, "%05d scalar int point", j); + HDsnprintf(name, sizeof(name), "%05d scalar int point", j); did = H5Dcreate(gid1, name, H5T_NATIVE_INT, sid_scalar, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &j); if (!j) @@ -372,7 +372,7 @@ create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsiz H5Dclose(did); /* 3 scalar vlen string */ - HDsprintf(name, "%05d scalar vlen string", j); + HDsnprintf(name, sizeof(name), "%05d scalar vlen string", j); did = H5Dcreate(gid1, name, tid_vlen_s, sid_scalar, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite(did, tid_vlen_s, H5S_ALL, H5S_ALL, H5P_DEFAULT, &buf_vlen_s[0]); if (!j) @@ -380,7 +380,7 @@ create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsiz H5Dclose(did); /* 4 add fixed-length float array */ - HDsprintf(name, "%05d fixed-length float array", j); + HDsnprintf(name, sizeof(name), "%05d fixed-length float array", j); did = H5Dcreate(gid1, name, tid_array_f, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Dwrite(did, tid_array_f, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_float_a); if (!j) @@ -388,7 +388,7 @@ create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsiz H5Dclose(did); /* 5 add fixed-length strings */ - HDsprintf(name, "%05d fixed-length strings", j); + HDsnprintf(name, sizeof(name), "%05d fixed-length strings", j); did = H5Dcreate(gid1, name, tid_str, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Dwrite(did, tid_str, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_str); if (!j) @@ -396,7 +396,7 @@ create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsiz H5Dclose(did); /* 6 add compound data */ - HDsprintf(name, "%05d compound data", j); + HDsnprintf(name, sizeof(name), "%05d compound data", j); did = H5Dcreate(gid1, name, cmp_tid, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Dwrite(did, cmp_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_comp); if (!j) @@ -404,7 +404,7 @@ create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsiz H5Dclose(did); /* 7 add 2D double */ - HDsprintf(name, "%05d 2D double", j); + HDsnprintf(name, sizeof(name), "%05d 2D double", j); strcpy(tmp_name1, name); did = H5Dcreate(gid1, name, H5T_NATIVE_DOUBLE, sid_2d, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite(did, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_double2d[0]); @@ -413,7 +413,7 @@ create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsiz H5Dclose(did); /* 8 add 1D int array */ - HDsprintf(name, "%05d 1D int array", j); + HDsnprintf(name, sizeof(name), "%05d 1D int array", j); did = H5Dcreate(gid1, name, H5T_NATIVE_INT, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_int); if (!j) @@ -421,7 +421,7 @@ create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsiz H5Dclose(did); /* 9 add vlen int array */ - HDsprintf(name, "%05d vlen int array", j); + HDsnprintf(name, sizeof(name), "%05d vlen int array", j); strcpy(tmp_name2, name); did = H5Dcreate(gid1, name, tid_vlen_i, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Dwrite(did, tid_vlen_i, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_vlen_i); @@ -430,7 +430,7 @@ create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsiz H5Dclose(did); /* 10 add vlen strings */ - HDsprintf(name, "%05d vlen strings", j); + HDsnprintf(name, sizeof(name), "%05d vlen strings", j); strcpy(tmp_name3, name); did = H5Dcreate(gid1, name, tid_vlen_s, sid_1d, H5P_DEFAULT, dcpl, H5P_DEFAULT); H5Dwrite(did, tid_vlen_s, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_vlen_s); @@ -441,7 +441,7 @@ create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsiz /* 11 add object refs */ H5Rcreate(&buf_ref[0], gid1, ".", H5R_OBJECT, (hid_t)-1); H5Rcreate(&buf_ref[1], gid1, tmp_name3, H5R_OBJECT, (hid_t)-1); - HDsprintf(name, "%05d obj refs", j); + HDsnprintf(name, sizeof(name), "%05d obj refs", j); did = H5Dcreate(gid1, name, H5T_STD_REF_OBJ, sid_2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite(did, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_ref); if (!j) @@ -456,7 +456,7 @@ create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsiz H5Sselect_hyperslab(sid_1d, H5S_SELECT_SET, &start, &stride, &count, NULL); H5Rcreate(&buf_reg_ref[1], gid1, tmp_name2, H5R_DATASET_REGION, sid_1d); H5Sselect_none(sid_1d); - HDsprintf(name, "%05d region refs", j); + HDsnprintf(name, sizeof(name), "%05d region refs", j); did = H5Dcreate(gid1, name, H5T_STD_REF_DSETREG, sid_2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite(did, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_reg_ref); if (!j) @@ -572,11 +572,11 @@ add_attrs(hid_t oid, int idx) /* 1 scalar point */ sid = H5Screate(H5S_SCALAR); - HDsprintf(name, "%05d scalar int", idx); + HDsnprintf(name, sizeof(name), "%05d scalar int", idx); nattrs += add_attr(oid, name, H5T_NATIVE_UINT, sid, &i); - HDsprintf(name, "%05d scalar ulong", idx); + HDsnprintf(name, sizeof(name), "%05d scalar ulong", idx); nattrs += add_attr(oid, name, H5T_NATIVE_INT64, sid, &l); - HDsprintf(name, "%05d scalar str", idx); + HDsnprintf(name, sizeof(name), "%05d scalar str", idx); tid = H5Tcopy(H5T_C_S1); H5Tset_size(tid, H5T_VARIABLE); nattrs += add_attr(oid, name, tid, sid, &s[2]); @@ -586,24 +586,24 @@ add_attrs(hid_t oid, int idx) /* 4 single point */ sid = H5Screate_simple(1, dims1, NULL); H5Rcreate(&ref, oid, ".", H5R_OBJECT, (hid_t)-1); - HDsprintf(name, "%05d single float", idx); + HDsnprintf(name, sizeof(name), "%05d single float", idx); nattrs += add_attr(oid, name, H5T_NATIVE_FLOAT, sid, &f); - HDsprintf(name, "%05d single double", idx); + HDsnprintf(name, sizeof(name), "%05d single double", idx); nattrs += add_attr(oid, name, H5T_NATIVE_DOUBLE, sid, &d); - HDsprintf(name, "%05d single obj_ref", idx); + HDsnprintf(name, sizeof(name), "%05d single obj_ref", idx); nattrs += add_attr(oid, name, H5T_STD_REF_OBJ, sid, &ref); H5Sclose(sid); /* 7 fixed length 1D array */ sid = H5Screate_simple(1, dims1, NULL); tid = H5Tarray_create(H5T_NATIVE_FLOAT, 1, dims2); - HDsprintf(name, "%05d array float", idx); + HDsnprintf(name, sizeof(name), "%05d array float", idx); nattrs += add_attr(oid, name, tid, sid, &f_array[0]); H5Tclose(tid); tid = H5Tcopy(H5T_C_S1); H5Tset_size(tid, strlen(s[0]) + 1); tid1 = H5Tarray_create(tid, 1, dims2); - HDsprintf(name, "%05d array str", idx); + HDsnprintf(name, sizeof(name), "%05d array str", idx); nattrs += add_attr(oid, name, tid1, sid, s); H5Tclose(tid1); H5Tclose(tid); @@ -612,7 +612,7 @@ add_attrs(hid_t oid, int idx) /* 9 fixed length 2D int arrays */ sid = H5Screate_simple(1, dims2, NULL); tid = H5Tarray_create(H5T_NATIVE_INT, 2, dims3); - HDsprintf(name, "%05d array int 2D", idx); + HDsnprintf(name, sizeof(name), "%05d array int 2D", idx); nattrs += add_attr(oid, name, tid, sid, int3d[0][0]); H5Tclose(tid); H5Sclose(sid); @@ -621,12 +621,12 @@ add_attrs(hid_t oid, int idx) sid = H5Screate_simple(1, dims2, NULL); tid = H5Tcopy(H5T_C_S1); H5Tset_size(tid, H5T_VARIABLE); - HDsprintf(name, "%05d vlen strings", idx); + HDsnprintf(name, sizeof(name), "%05d vlen strings", idx); nattrs += add_attr(oid, name, tid, sid, s_vlen); H5Tclose(tid); tid = H5Tvlen_create(H5T_NATIVE_INT); ; - HDsprintf(name, "%05d vlen int array", idx); + HDsnprintf(name, sizeof(name), "%05d vlen int array", idx); nattrs += add_attr(oid, name, tid, sid, i_vlen); H5Tclose(tid); H5Sclose(sid); @@ -640,7 +640,7 @@ add_attrs(hid_t oid, int idx) offset += sizeof(H5T_NATIVE_INT); H5Tinsert(tid, "City", offset, tid1); offset += sizeof(char *); - HDsprintf(name, "%05d compound data", idx); + HDsnprintf(name, sizeof(name), "%05d compound data", idx); nattrs += add_attr(oid, name, tid, sid, cmp_data); H5Tclose(tid1); H5Tclose(tid); diff --git a/tools/test/perform/iopipe.c b/tools/test/perform/iopipe.c index 2aa9e25..37f07a1 100644 --- a/tools/test/perform/iopipe.c +++ b/tools/test/perform/iopipe.c @@ -71,7 +71,7 @@ print_stats(const char *prefix, ((double)(r_start->ru_stime.tv_sec) + (double)(r_start->ru_stime.tv_usec) / 1000000.0); #endif e_time = t_stop - t_start; - H5_bandwidth(bw, (double)nbytes, e_time); + H5_bandwidth(bw, sizeof(bw), (double)nbytes, e_time); #ifdef H5_HAVE_GETRUSAGE HDprintf(HEADING "%1.2fuser %1.2fsystem %1.2felapsed %s\n", prefix, u_time, s_time, e_time, bw); -- cgit v0.12