Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/top bound string operations



details:   https://anonhg.NetBSD.org/src/rev/b6536fadd7b6
branches:  trunk
changeset: 549339:b6536fadd7b6
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sat Jul 12 14:08:37 2003 +0000

description:
bound string operations

diffstat:

 usr.bin/top/commands.c |  15 ++++++++-------
 usr.bin/top/utils.c    |  12 +++++++-----
 usr.bin/top/version.c  |   8 ++++----
 3 files changed, 19 insertions(+), 16 deletions(-)

diffs (125 lines):

diff -r 1f4fce1c1f9d -r b6536fadd7b6 usr.bin/top/commands.c
--- a/usr.bin/top/commands.c    Sat Jul 12 13:57:49 2003 +0000
+++ b/usr.bin/top/commands.c    Sat Jul 12 14:08:37 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: commands.c,v 1.9 2003/06/23 13:05:52 agc Exp $ */
+/*     $NetBSD: commands.c,v 1.10 2003/07/12 14:08:37 itojun Exp $     */
 
 /*
  *  Top users/processes display for Unix
@@ -37,7 +37,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: commands.c,v 1.9 2003/06/23 13:05:52 agc Exp $");
+__RCSID("$NetBSD: commands.c,v 1.10 2003/07/12 14:08:37 itojun Exp $");
 #endif
 
 #include "os.h"
@@ -253,7 +253,8 @@
                {
                    return(err_listem);
                }
-               (void) strcat(string, "; ");      /* we know there's more */
+               /* we know there's more */
+               (void) strlcat(string, "; ", sizeof(string));
            }
            currerr = errp->errnum;
            first = Yes;
@@ -294,8 +295,8 @@
     {
        return(0);
     }
-    (void) strcat(str, ": ");
-    (void) strcat(str, msg);
+    (void) strlcat(str, ": ", len);
+    (void) strlcat(str, msg, len);
     return(len - msglen);
 }
 
@@ -327,9 +328,9 @@
     }
     if (!first)
     {
-       (void) strcat(str, ", ");
+       (void) strlcat(str, ", ", len);
     }
-    (void) strcat(str, arg);
+    (void) strlcat(str, arg, len);
     return(len - arglen);
 }
 
diff -r 1f4fce1c1f9d -r b6536fadd7b6 usr.bin/top/utils.c
--- a/usr.bin/top/utils.c       Sat Jul 12 13:57:49 2003 +0000
+++ b/usr.bin/top/utils.c       Sat Jul 12 14:08:37 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: utils.c,v 1.6 2003/06/23 13:05:53 agc Exp $    */
+/*     $NetBSD: utils.c,v 1.7 2003/07/12 14:08:37 itojun Exp $ */
 
 /*
  *  Top users/processes display for Unix
@@ -34,7 +34,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: utils.c,v 1.6 2003/06/23 13:05:53 agc Exp $");
+__RCSID("$NetBSD: utils.c,v 1.7 2003/07/12 14:08:37 itojun Exp $");
 #endif
 
 #include "os.h"
@@ -412,12 +412,13 @@
     /* sanity protection */
     if (seconds < 0 || seconds > (99999l * 360l))
     {
-       strcpy(result, "   ???");
+       strlcpy(result, "   ???", sizeof(result));
     }
     else if (seconds >= (1000l * 60l))
     {
        /* alternate (slow) method displaying hours and tenths */
-       sprintf(result, "%5.1fH", (double)seconds / (double)(60l * 60l));
+       snprintf(result, sizeof(result), "%5.1fH",
+           (double)seconds / (double)(60l * 60l));
 
        /* It is possible that the sprintf took more than 6 characters.
           If so, then the "H" appears as result[6].  If not, then there
@@ -429,7 +430,8 @@
     {
        /* standard method produces MMM:SS */
        /* we avoid printf as must as possible to make this quick */
-       sprintf(result, "%3ld:%02ld", seconds / 60l, seconds % 60l);
+       snprintf(result, sizeof(result), "%3ld:%02ld", seconds / 60l,
+           seconds % 60l);
     }
     return(result);
 }
diff -r 1f4fce1c1f9d -r b6536fadd7b6 usr.bin/top/version.c
--- a/usr.bin/top/version.c     Sat Jul 12 13:57:49 2003 +0000
+++ b/usr.bin/top/version.c     Sat Jul 12 14:08:37 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: version.c,v 1.5 2003/06/23 13:05:53 agc Exp $  */
+/*     $NetBSD: version.c,v 1.6 2003/07/12 14:08:38 itojun Exp $       */
 
 /*
  *  Top users/processes display for Unix
@@ -30,7 +30,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: version.c,v 1.5 2003/06/23 13:05:53 agc Exp $");
+__RCSID("$NetBSD: version.c,v 1.6 2003/07/12 14:08:38 itojun Exp $");
 #endif
 
 #include "os.h"
@@ -42,9 +42,9 @@
 char *version_string()
 
 {
-    sprintf(version, "%d.%d", VERSION, PATCHLEVEL);
+    snprintf(version, sizeof(version), "%d.%d", VERSION, PATCHLEVEL);
 #ifdef BETA
-    strcat(version, BETA);
+    strlcat(version, BETA, sizeof(version));
 #endif
     return(version);
 }



Home | Main Index | Thread Index | Old Index