summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSean McBride <sean@rogue-research.com>2022-01-28 16:34:57 (GMT)
committerGitHub <noreply@github.com>2022-01-28 16:34:57 (GMT)
commitb5eed1b56324fc07154c2e2d8251d2b87505ca23 (patch)
treeb3e3840a886966ae07e50a69ab7492ebe4df876c /src
parent44de59b642c4d5ccf505a1072d10b63dc9fe0628 (diff)
downloadhdf5-b5eed1b56324fc07154c2e2d8251d2b87505ca23.zip
hdf5-b5eed1b56324fc07154c2e2d8251d2b87505ca23.tar.gz
hdf5-b5eed1b56324fc07154c2e2d8251d2b87505ca23.tar.bz2
Replaced several uses of sprintf with safer snprintf (#1383)
* Replaced several uses of sprintf with safer snprintf * Committing clang-format changes Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r--src/H5AC.c2
-rw-r--r--src/H5Dchunk.c4
-rw-r--r--src/H5Dearray.c4
-rw-r--r--src/H5Dfarray.c4
-rw-r--r--src/H5EAdbg.c6
-rw-r--r--src/H5EAtest.c2
-rw-r--r--src/H5FAtest.c2
-rw-r--r--src/H5FDmulti.c6
-rw-r--r--src/H5RS.c2
-rw-r--r--src/H5VLpassthru.c13
-rw-r--r--src/H5private.h2
11 files changed, 22 insertions, 25 deletions
diff --git a/src/H5AC.c b/src/H5AC.c
index e20be3b..47d3a65 100644
--- a/src/H5AC.c
+++ b/src/H5AC.c
@@ -303,7 +303,7 @@ H5AC_create(const H5F_t *f, H5AC_cache_config_t *config_ptr, H5AC_cache_image_co
aux_ptr->sync_point_done = NULL;
aux_ptr->p0_image_len = 0;
- HDsprintf(prefix, "%d:", mpi_rank);
+ HDsnprintf(prefix, sizeof(prefix), "%d:", mpi_rank);
if (mpi_rank == 0) {
if (NULL == (aux_ptr->d_slist_ptr = H5SL_create(H5SL_TYPE_HADDR, NULL)))
diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c
index b85b194..5d7c1b2 100644
--- a/src/H5Dchunk.c
+++ b/src/H5Dchunk.c
@@ -6696,10 +6696,10 @@ H5D__chunk_stats(const H5D_t *dset, hbool_t headers)
miss_rate = 0.0;
}
if (miss_rate > 100) {
- HDsprintf(ascii, "%7d%%", (int)(miss_rate + 0.5));
+ HDsnprintf(ascii, sizeof(ascii), "%7d%%", (int)(miss_rate + 0.5));
}
else {
- HDsprintf(ascii, "%7.2f%%", miss_rate);
+ HDsnprintf(ascii, sizeof(ascii), "%7.2f%%", miss_rate);
}
HDfprintf(H5DEBUG(AC), " %-18s %8u %8u %7s %8d+%-9ld\n", "raw data chunks", rdcc->stats.nhits,
diff --git a/src/H5Dearray.c b/src/H5Dearray.c
index abce233..cd52b66 100644
--- a/src/H5Dearray.c
+++ b/src/H5Dearray.c
@@ -417,7 +417,7 @@ H5D__earray_debug(FILE *stream, int indent, int fwidth, hsize_t idx, const void
HDassert(elmt);
/* Print element */
- HDsprintf(temp_str, "Element #%" PRIuHSIZE ":", idx);
+ HDsnprintf(temp_str, sizeof(temp_str), "Element #%" PRIuHSIZE ":", idx);
HDfprintf(stream, "%*s%-*s %" PRIuHADDR "\n", indent, "", fwidth, temp_str, *(const haddr_t *)elmt);
FUNC_LEAVE_NOAPI(SUCCEED)
@@ -573,7 +573,7 @@ H5D__earray_filt_debug(FILE *stream, int indent, int fwidth, hsize_t idx, const
HDassert(elmt);
/* Print element */
- HDsprintf(temp_str, "Element #%" PRIuHSIZE ":", idx);
+ HDsnprintf(temp_str, sizeof(temp_str), "Element #%" PRIuHSIZE ":", idx);
HDfprintf(stream, "%*s%-*s {%" PRIuHADDR ", %u, %0x}\n", indent, "", fwidth, temp_str, elmt->addr,
elmt->nbytes, elmt->filter_mask);
diff --git a/src/H5Dfarray.c b/src/H5Dfarray.c
index 0741e8f..ab0f0f8 100644
--- a/src/H5Dfarray.c
+++ b/src/H5Dfarray.c
@@ -415,7 +415,7 @@ H5D__farray_debug(FILE *stream, int indent, int fwidth, hsize_t idx, const void
HDassert(elmt);
/* Print element */
- HDsprintf(temp_str, "Element #%" PRIuHSIZE ":", idx);
+ HDsnprintf(temp_str, sizeof(temp_str), "Element #%" PRIuHSIZE ":", idx);
HDfprintf(stream, "%*s%-*s %" PRIuHADDR "\n", indent, "", fwidth, temp_str, *(const haddr_t *)elmt);
FUNC_LEAVE_NOAPI(SUCCEED)
@@ -675,7 +675,7 @@ H5D__farray_filt_debug(FILE *stream, int indent, int fwidth, hsize_t idx, const
HDassert(elmt);
/* Print element */
- HDsprintf(temp_str, "Element #%" PRIuHSIZE ":", idx);
+ HDsnprintf(temp_str, sizeof(temp_str), "Element #%" PRIuHSIZE ":", idx);
HDfprintf(stream, "%*s%-*s {%" PRIuHADDR ", %u, %0x}\n", indent, "", fwidth, temp_str, elmt->addr,
elmt->nbytes, elmt->filter_mask);
diff --git a/src/H5EAdbg.c b/src/H5EAdbg.c
index b0e564c..b377422 100644
--- a/src/H5EAdbg.c
+++ b/src/H5EAdbg.c
@@ -237,7 +237,7 @@ H5EA__iblock_debug(H5F_t *f, haddr_t H5_ATTR_UNUSED addr, FILE *stream, int inde
HDfprintf(stream, "%*sData Block Addresses in Index Block:\n", indent, "");
for (u = 0; u < iblock->ndblk_addrs; u++) {
/* Print address */
- HDsprintf(temp_str, "Address #%u:", u);
+ HDsnprintf(temp_str, sizeof(temp_str), "Address #%u:", u);
HDfprintf(stream, "%*s%-*s %" PRIuHADDR "\n", (indent + 3), "", MAX(0, (fwidth - 3)), temp_str,
iblock->dblk_addrs[u]);
} /* end for */
@@ -252,7 +252,7 @@ H5EA__iblock_debug(H5F_t *f, haddr_t H5_ATTR_UNUSED addr, FILE *stream, int inde
HDfprintf(stream, "%*sSuper Block Addresses in Index Block:\n", indent, "");
for (u = 0; u < iblock->nsblk_addrs; u++) {
/* Print address */
- HDsprintf(temp_str, "Address #%u:", u);
+ HDsnprintf(temp_str, sizeof(temp_str), "Address #%u:", u);
HDfprintf(stream, "%*s%-*s %" PRIuHADDR "\n", (indent + 3), "", MAX(0, (fwidth - 3)), temp_str,
iblock->sblk_addrs[u]);
} /* end for */
@@ -341,7 +341,7 @@ H5EA__sblock_debug(H5F_t *f, haddr_t addr, FILE *stream, int indent, int fwidth,
HDfprintf(stream, "%*sData Block Addresses in Super Block:\n", indent, "");
for (u = 0; u < sblock->ndblks; u++) {
/* Print address */
- HDsprintf(temp_str, "Address #%u:", u);
+ HDsnprintf(temp_str, sizeof(temp_str), "Address #%u:", u);
HDfprintf(stream, "%*s%-*s %" PRIuHADDR "\n", (indent + 3), "", MAX(0, (fwidth - 3)), temp_str,
sblock->dblk_addrs[u]);
} /* end for */
diff --git a/src/H5EAtest.c b/src/H5EAtest.c
index 7924eaa..24efbc2 100644
--- a/src/H5EAtest.c
+++ b/src/H5EAtest.c
@@ -322,7 +322,7 @@ H5EA__test_debug(FILE *stream, int indent, int fwidth, hsize_t idx, const void *
HDassert(elmt);
/* Print element */
- HDsprintf(temp_str, "Element #%llu:", (unsigned long long)idx);
+ HDsnprintf(temp_str, sizeof(temp_str), "Element #%llu:", (unsigned long long)idx);
HDfprintf(stream, "%*s%-*s %llu\n", indent, "", fwidth, temp_str,
(unsigned long long)*(const uint64_t *)elmt);
diff --git a/src/H5FAtest.c b/src/H5FAtest.c
index 384a657..b57f562 100644
--- a/src/H5FAtest.c
+++ b/src/H5FAtest.c
@@ -303,7 +303,7 @@ H5FA__test_debug(FILE *stream, int indent, int fwidth, hsize_t idx, const void *
HDassert(elmt);
/* Print element */
- HDsprintf(temp_str, "Element #%llu:", (unsigned long long)idx);
+ HDsnprintf(temp_str, sizeof(temp_str), "Element #%llu:", (unsigned long long)idx);
HDfprintf(stream, "%*s%-*s %llu\n", indent, "", fwidth, temp_str,
(unsigned long long)*(const uint64_t *)elmt);
diff --git a/src/H5FDmulti.c b/src/H5FDmulti.c
index 3dcfa37..d9a6ce9 100644
--- a/src/H5FDmulti.c
+++ b/src/H5FDmulti.c
@@ -517,7 +517,7 @@ H5FD_split_populate_config(const char *meta_ext, hid_t meta_plist_id, const char
meta_name_g[sizeof(meta_name_g) - 1] = '\0';
}
else
- sprintf(meta_name_g, "%%s%s", meta_ext);
+ snprintf(meta_name_g, sizeof(meta_name_g), "%%s%s", meta_ext);
}
else {
strncpy(meta_name_g, "%s.meta", sizeof(meta_name_g));
@@ -535,7 +535,7 @@ H5FD_split_populate_config(const char *meta_ext, hid_t meta_plist_id, const char
raw_name_g[sizeof(raw_name_g) - 1] = '\0';
}
else
- sprintf(raw_name_g, "%%s%s", raw_ext);
+ snprintf(raw_name_g, sizeof(raw_name_g), "%%s%s", raw_ext);
}
else {
strncpy(raw_name_g, "%s.raw", sizeof(raw_name_g));
@@ -634,7 +634,7 @@ H5FD_multi_populate_config(const H5FD_mem_t *memb_map, const hid_t *memb_fapl, c
if (!memb_name) {
assert(strlen(letters) == H5FD_MEM_NTYPES);
for (mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; mt = (H5FD_mem_t)(mt + 1)) {
- sprintf(_memb_name_g[mt], "%%s-%c.h5", letters[mt]);
+ snprintf(_memb_name_g[mt], 16, "%%s-%c.h5", letters[mt]);
_memb_name_ptrs[mt] = _memb_name_g[mt];
}
memb_name = _memb_name_ptrs;
diff --git a/src/H5RS.c b/src/H5RS.c
index 117c8ea..16c2356 100644
--- a/src/H5RS.c
+++ b/src/H5RS.c
@@ -350,7 +350,7 @@ done:
*/
/* Disable warning for "format not a string literal" here -QAK */
/*
- * This pragma only needs to surround the sprintf() calls with
+ * This pragma only needs to surround the snprintf() calls with
* format_templ in the code below, but early (4.4.7, at least) gcc only
* allows diagnostic pragmas to be toggled outside of functions.
*/
diff --git a/src/H5VLpassthru.c b/src/H5VLpassthru.c
index 6b4c59f..6eda875 100644
--- a/src/H5VLpassthru.c
+++ b/src/H5VLpassthru.c
@@ -641,16 +641,13 @@ H5VL_pass_through_info_to_str(const void *_info, char **str)
under_vol_str_len = strlen(under_vol_string);
/* Allocate space for our info */
- *str = (char *)H5allocate_memory(32 + under_vol_str_len, (hbool_t)0);
+ size_t strSize = 32 + under_vol_str_len;
+ *str = (char *)H5allocate_memory(strSize, (hbool_t)0);
assert(*str);
- /* Encode our info
- * Normally we'd use snprintf() here for a little extra safety, but that
- * call had problems on Windows until recently. So, to be as platform-independent
- * as we can, we're using sprintf() instead.
- */
- sprintf(*str, "under_vol=%u;under_info={%s}", (unsigned)under_value,
- (under_vol_string ? under_vol_string : ""));
+ /* Encode our info */
+ snprintf(*str, strSize, "under_vol=%u;under_info={%s}", (unsigned)under_value,
+ (under_vol_string ? under_vol_string : ""));
return 0;
} /* end H5VL_pass_through_info_to_str() */
diff --git a/src/H5private.h b/src/H5private.h
index 5b0e33b..fa52e7f 100644
--- a/src/H5private.h
+++ b/src/H5private.h
@@ -172,7 +172,7 @@
*/
#define BEGIN_MPE_LOG \
if (H5_MPEinit_g) { \
- sprintf(p_event_start, "start %s", __func__); \
+ snprintf(p_event_start, sizeof(p_event_start), "start %s", __func__); \
if (eventa(__func__) == -1 && eventb(__func__) == -1) { \
const char *p_color = "red"; \
eventa(__func__) = MPE_Log_get_event_number(); \