]> git.gsnw.org Git - fping.git/commitdiff
Fix: OpenBSD sprintf warning
authorGerman Service Network <support@gsnw.de>
Sat, 17 May 2025 19:33:19 +0000 (21:33 +0200)
committerSebastian <176771227+gsnw-sebast@users.noreply.github.com>
Sun, 25 May 2025 06:01:28 +0000 (08:01 +0200)
CHANGELOG.md
src/fping.c

index f0cb0207b88be04aef4cb406813ea437efbebf48..a9e163af53a30a689dcd3616a1076ca011948523 100644 (file)
@@ -8,6 +8,7 @@ Next
 
 ## Bugfixes and other changes
 
+- Fix OpenBSD warning sprintf() is often misused, please use snprintf() (#394, thanks @gsnw-sebast)
 - Fix fallback to SO\_TIMESTAMP if SO\_TIMESTAMPNS is not available (#375,
   thanks @auerswal)
 
index 8433d08927797a4abe4b1fc71fdc0a7ce2a8962e..c71a4e8647218d969a05989e7e995f50720e16db 100644 (file)
@@ -3127,26 +3127,26 @@ const char *sprint_tm(int64_t ns)
 
     if (t < 0.0) {
         /* negative (unexpected) */
-        sprintf(buf, "%.2g", t);
+        snprintf(buf, sizeof(buf), "%.2g", t);
     }
     else if (t < 1.0) {
         /* <= 0.99 ms */
-        sprintf(buf, "%.3f", t);
+        snprintf(buf, sizeof(buf), "%.3f", t);
     }
     else if (t < 10.0) {
         /* 1.00 - 9.99 ms */
-        sprintf(buf, "%.2f", t);
+        snprintf(buf, sizeof(buf), "%.2f", t);
     }
     else if (t < 100.0) {
         /* 10.0 - 99.9 ms */
-        sprintf(buf, "%.1f", t);
+        snprintf(buf, sizeof(buf), "%.1f", t);
     }
     else if (t < 1000000.0) {
         /* 100 - 1'000'000 ms */
-        sprintf(buf, "%.0f", t);
+        snprintf(buf, sizeof(buf), "%.0f", t);
     }
     else {
-        sprintf(buf, "%.3e", t);
+        snprintf(buf, sizeof(buf), "%.3e", t);
     }
 
     return (buf);