diff options
author | Sean McBride <sean@rogue-research.com> | 2022-06-22 18:58:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-22 18:58:18 (GMT) |
commit | c064d3481b582653c1e0d0043a17527fd73e8c4d (patch) | |
tree | 396a5e13954c19b803aa80465938cde15140b176 /src/H5timer.c | |
parent | d6f05069c1a3642bbebf7ec27e7df809f0675f13 (diff) | |
download | hdf5-c064d3481b582653c1e0d0043a17527fd73e8c4d.zip hdf5-c064d3481b582653c1e0d0043a17527fd73e8c4d.tar.gz hdf5-c064d3481b582653c1e0d0043a17527fd73e8c4d.tar.bz2 |
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>
Diffstat (limited to 'src/H5timer.c')
-rw-r--r-- | src/H5timer.c | 39 |
1 files changed, 20 insertions, 19 deletions
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() */ |