summaryrefslogtreecommitdiffstats
path: root/utils/tools
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 /utils/tools
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 'utils/tools')
-rw-r--r--utils/tools/h5dwalk/h5dwalk.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/utils/tools/h5dwalk/h5dwalk.c b/utils/tools/h5dwalk/h5dwalk.c
index d7e22ba..5a22d75 100644
--- a/utils/tools/h5dwalk/h5dwalk.c
+++ b/utils/tools/h5dwalk/h5dwalk.c
@@ -1071,12 +1071,12 @@ run_command(int argc __attribute__((unused)), char **argv, char *cmdline, const
if ((log_instance > 0) || processing_inputfile) {
if (processing_inputfile)
log_instance = current_input_index;
- HDsprintf(logpath, "%s/%s_%s.log_%d", HDgetcwd(current_dir, sizeof(current_dir)), logbase,
- thisapp, log_instance);
+ HDsnprintf(logpath, sizeof(logpath), "%s/%s_%s.log_%d",
+ HDgetcwd(current_dir, sizeof(current_dir)), logbase, thisapp, log_instance);
}
else {
- HDsprintf(logpath, "%s/%s_%s.log", HDgetcwd(current_dir, sizeof(current_dir)), logbase,
- thisapp);
+ HDsnprintf(logpath, sizeof(logpath), "%s/%s_%s.log",
+ HDgetcwd(current_dir, sizeof(current_dir)), logbase, thisapp);
}
}
else {
@@ -1085,15 +1085,17 @@ run_command(int argc __attribute__((unused)), char **argv, char *cmdline, const
if (processing_inputfile)
log_instance = current_input_index;
if (txtlog[log_len - 1] == '/')
- HDsprintf(logpath, "%s%s_%s.log_%d", txtlog, logbase, thisapp, log_instance);
+ HDsnprintf(logpath, sizeof(logpath), "%s%s_%s.log_%d", txtlog, logbase, thisapp,
+ log_instance);
else
- HDsprintf(logpath, "%s/%s_%s.log_%d", txtlog, logbase, thisapp, log_instance);
+ HDsnprintf(logpath, sizeof(logpath), "%s/%s_%s.log_%d", txtlog, logbase, thisapp,
+ log_instance);
}
else {
if (txtlog[log_len - 1] == '/')
- HDsprintf(logpath, "%s%s_%s.log", txtlog, logbase, thisapp);
+ HDsnprintf(logpath, sizeof(logpath), "%s%s_%s.log", txtlog, logbase, thisapp);
else
- HDsprintf(logpath, "%s/%s_%s.log", txtlog, logbase, thisapp);
+ HDsnprintf(logpath, sizeof(logpath), "%s/%s_%s.log", txtlog, logbase, thisapp);
}
}
@@ -1204,7 +1206,7 @@ MFU_PRED_EXEC(mfu_flist flist, uint64_t idx, void *arg)
}
}
- HDsprintf(cmdline, "\n---------\nCommand:");
+ HDsnprintf(cmdline, sizeof(cmdline), "\n---------\nCommand:");
b_offset = strlen(cmdline);
for (k = 0; k < count; k++) {
HDsprintf(&cmdline[b_offset], " %s", argv[k]);
@@ -1242,7 +1244,7 @@ static void
add_executable(int argc, char **argv, char *cmdstring, int *f_index, int f_count __attribute__((unused)))
{
char cmdline[2048];
- HDsprintf(cmdline, "\n---------\nCommand: %s\n", cmdstring);
+ HDsnprintf(cmdline, sizeof(cmdline), "\n---------\nCommand: %s\n", cmdstring);
argv[argc] = NULL;
run_command(argc, argv, cmdline, argv[f_index[0]]);
return;