summaryrefslogtreecommitdiffstats
path: root/c++/test
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 /c++/test
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 'c++/test')
-rw-r--r--c++/test/tattr.cpp6
-rw-r--r--c++/test/titerate.cpp2
-rw-r--r--c++/test/tvlstr.cpp10
3 files changed, 9 insertions, 9 deletions
diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp
index 5627341..dc968f9 100644
--- a/c++/test/tattr.cpp
+++ b/c++/test/tattr.cpp
@@ -1782,7 +1782,7 @@ test_attr_dense_create(FileCreatPropList &fcpl, FileAccPropList &fapl)
unsigned attr_num;
for (attr_num = 0; attr_num < max_compact; attr_num++) {
// Create attribute
- sprintf(attr_name, "attr %02u", attr_num);
+ snprintf(attr_name, sizeof(attr_name), "attr %02u", attr_num);
Attribute attr = dataset.createAttribute(attr_name, PredType::NATIVE_UINT, ds_space);
// Write data to the attribute
@@ -1794,7 +1794,7 @@ test_attr_dense_create(FileCreatPropList &fcpl, FileAccPropList &fapl)
{ // Add one more attribute, to push into "dense" storage
// Create another attribute
- sprintf(attr_name, "attr %02u", attr_num);
+ snprintf(attr_name, sizeof(attr_name), "attr %02u", attr_num);
Attribute attr = dataset.createAttribute(attr_name, PredType::NATIVE_UINT, ds_space);
// Write data to the attribute
@@ -1804,7 +1804,7 @@ test_attr_dense_create(FileCreatPropList &fcpl, FileAccPropList &fapl)
// Attempt to add attribute again, which should fail
try {
// Create another attribute
- sprintf(attr_name, "attr %02u", attr_num);
+ snprintf(attr_name, sizeof(attr_name), "attr %02u", attr_num);
Attribute attr = dataset.createAttribute(attr_name, PredType::NATIVE_UINT, ds_space);
// continuation here, that means no exception has been thrown
diff --git a/c++/test/titerate.cpp b/c++/test/titerate.cpp
index b6a9436..bc4d892 100644
--- a/c++/test/titerate.cpp
+++ b/c++/test/titerate.cpp
@@ -160,7 +160,7 @@ test_iter_group(FileAccPropList &fapl)
DataSpace filespace;
for (int i = 0; i < NDATASETS; i++) {
- sprintf(name, "Dataset %d", i);
+ snprintf(name, sizeof(name), "Dataset %d", i);
// Create a dataset in the file
DataSet dataset = file.createDataSet(name, datatype, filespace);
diff --git a/c++/test/tvlstr.cpp b/c++/test/tvlstr.cpp
index c91b566..405ca07 100644
--- a/c++/test/tvlstr.cpp
+++ b/c++/test/tvlstr.cpp
@@ -917,32 +917,32 @@ test_vl_rewrite()
int i;
char name[256]; // Buffer for names & data
for (i = 0; i < REWRITE_NDATASETS; i++) {
- sprintf(name, "/set_%d", i);
+ snprintf(name, sizeof(name), "/set_%d", i);
write_scalar_dset(file1, type, space, name, name);
}
// Effectively copy data from file 1 to 2.
for (i = 0; i < REWRITE_NDATASETS; i++) {
- sprintf(name, "/set_%d", i);
+ snprintf(name, sizeof(name), "/set_%d", i);
read_scalar_dset(file1, type, space, name, name);
write_scalar_dset(file2, type, space, name, name);
}
// Read back from file 2.
for (i = 0; i < REWRITE_NDATASETS; i++) {
- sprintf(name, "/set_%d", i);
+ snprintf(name, sizeof(name), "/set_%d", i);
read_scalar_dset(file2, type, space, name, name);
}
// Remove from file 2.
for (i = 0; i < REWRITE_NDATASETS; i++) {
- sprintf(name, "/set_%d", i);
+ snprintf(name, sizeof(name), "/set_%d", i);
file2.unlink(name);
}
// Effectively copy from file 1 to file 2.
for (i = 0; i < REWRITE_NDATASETS; i++) {
- sprintf(name, "/set_%d", i);
+ snprintf(name, sizeof(name), "/set_%d", i);
read_scalar_dset(file1, type, space, name, name);
write_scalar_dset(file2, type, space, name, name);
}