summaryrefslogtreecommitdiffstats
path: root/hl
diff options
context:
space:
mode:
authorSean McBride <sean@rogue-research.com>2022-01-28 22:43:48 (GMT)
committerGitHub <noreply@github.com>2022-01-28 22:43:48 (GMT)
commit4ac6ccc0213767be935b2686524937ae93c46e3f (patch)
tree9cd332106bd623c05f8e6837bed0d1ceab5ad7e9 /hl
parentad71539d30c799c497953c18352df37d83a75310 (diff)
downloadhdf5-4ac6ccc0213767be935b2686524937ae93c46e3f.zip
hdf5-4ac6ccc0213767be935b2686524937ae93c46e3f.tar.gz
hdf5-4ac6ccc0213767be935b2686524937ae93c46e3f.tar.bz2
Snprintf2 (#1399)
* Replaced many uses of sprintf with safer snprintf Many very straightforward, but in a few cases added a length parameter to some private functions, because buffer length was otherwise unknowable. * Removed unnecessary use of static on small buffers This improves thread safety. * Committing clang-format changes Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'hl')
-rw-r--r--hl/c++/test/ptableTest.cpp2
-rw-r--r--hl/test/test_file_image.c5
-rw-r--r--hl/test/test_packet_vlen.c16
3 files changed, 12 insertions, 11 deletions
diff --git a/hl/c++/test/ptableTest.cpp b/hl/c++/test/ptableTest.cpp
index 9db56e0..33199f1 100644
--- a/hl/c++/test/ptableTest.cpp
+++ b/hl/c++/test/ptableTest.cpp
@@ -622,7 +622,7 @@ TestHDFFV_9758()
s1[i].a = static_cast<int>(i);
s1[i].b = 1.0F * static_cast<float>(i * i);
s1[i].c = 1.0 / static_cast<double>(i + 1);
- HDsprintf(s1[i].d, "string%" PRIuHSIZE "", i);
+ HDsnprintf(s1[i].d, STRING_LENGTH, "string%" PRIuHSIZE "", i);
s1[i].e = static_cast<int>(100 + i);
}
diff --git a/hl/test/test_file_image.c b/hl/test/test_file_image.c
index 6bb36e4..4448e41 100644
--- a/hl/test/test_file_image.c
+++ b/hl/test/test_file_image.c
@@ -109,12 +109,13 @@ test_file_image(size_t open_images, size_t nflags, const unsigned *flags)
input_flags[i] = flags[(nflags + i) % nflags];
/* allocate name buffer for image i */
- filename[i] = (char *)HDmalloc(sizeof(char) * 32);
+ size_t filenamelength = sizeof(char) * 32;
+ filename[i] = (char *)HDmalloc(filenamelength);
if (!filename[i])
FAIL_PUTS_ERROR("HDmalloc() failed");
/* create file name */
- HDsprintf(filename[i], "image_file%d.h5", (int)i);
+ HDsnprintf(filename[i], filenamelength, "image_file%d.h5", (int)i);
/* create file */
if ((file_id[i] = H5Fcreate(filename[i], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
diff --git a/hl/test/test_packet_vlen.c b/hl/test/test_packet_vlen.c
index e704944..aa88a6c 100644
--- a/hl/test/test_packet_vlen.c
+++ b/hl/test/test_packet_vlen.c
@@ -109,7 +109,7 @@ test_VLof_atomic(void)
if (ret < 0)
goto error;
- HDsprintf(msg, "The number of packets in the packet table must be %u\n", NRECORDS);
+ HDsnprintf(msg, sizeof(msg), "The number of packets in the packet table must be %u\n", NRECORDS);
VERIFY(count == NRECORDS, msg);
/* Read all five packets back */
@@ -246,7 +246,7 @@ test_VLof_comptype(void)
if (ret < 0)
goto error;
- HDsprintf(msg, "The number of packets in the packet table must be %u\n", NRECORDS);
+ HDsnprintf(msg, sizeof(msg), "The number of packets in the packet table must be %u\n", NRECORDS);
VERIFY(count == NRECORDS, msg);
/* Read all five packets back */
@@ -418,7 +418,7 @@ test_compound_VL_VLtype(void)
if (ret < 0)
goto error;
- HDsprintf(msg, "The number of packets in the packet table must be %u\n", NRECORDS);
+ HDsnprintf(msg, sizeof(msg), "The number of packets in the packet table must be %u\n", NRECORDS);
VERIFY(count == NRECORDS, msg);
/* Read all five packets back */
@@ -582,7 +582,7 @@ test_VLof_VLtype(void)
if (ret < 0)
goto error;
- HDsprintf(msg, "The number of packets in the packet table must be %u\n", NRECORDS);
+ HDsnprintf(msg, sizeof(msg), "The number of packets in the packet table must be %u\n", NRECORDS);
VERIFY(count == NRECORDS, msg);
/* Read all five packets back */
@@ -1144,7 +1144,7 @@ testfl_VLof_atomic(void)
if (ret < 0)
goto error;
- HDsprintf(msg, "The number of packets in the packet table must be %u\n", NRECORDS);
+ HDsnprintf(msg, sizeof(msg), "The number of packets in the packet table must be %u\n", NRECORDS);
VERIFY(count == NRECORDS, msg);
/* Read all five packets back */
@@ -1281,7 +1281,7 @@ testfl_VLof_comptype(void)
if (ret < 0)
goto error;
- HDsprintf(msg, "The number of packets in the packet table must be %u\n", NRECORDS);
+ HDsnprintf(msg, sizeof(msg), "The number of packets in the packet table must be %u\n", NRECORDS);
VERIFY(count == NRECORDS, msg);
/* Read all five packets back */
@@ -1453,7 +1453,7 @@ testfl_compound_VL_VLtype(void)
if (ret < 0)
goto error;
- HDsprintf(msg, "The number of packets in the packet table must be %u\n", NRECORDS);
+ HDsnprintf(msg, sizeof(msg), "The number of packets in the packet table must be %u\n", NRECORDS);
VERIFY(count == NRECORDS, msg);
/* Read all five packets back */
@@ -1617,7 +1617,7 @@ testfl_VLof_VLtype(void)
if (ret < 0)
goto error;
- HDsprintf(msg, "The number of packets in the packet table must be %u\n", NRECORDS);
+ HDsnprintf(msg, sizeof(msg), "The number of packets in the packet table must be %u\n", NRECORDS);
VERIFY(count == NRECORDS, msg);
/* Read all five packets back */