Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/systat eliminate non-literal format strings.



details:   https://anonhg.NetBSD.org/src/rev/24a8cf5f7d3d
branches:  trunk
changeset: 768480:24a8cf5f7d3d
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Aug 17 13:26:49 2011 +0000

description:
eliminate non-literal format strings.

diffstat:

 usr.bin/systat/ps.c |  17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)

diffs (49 lines):

diff -r 6be9f8476648 -r 24a8cf5f7d3d usr.bin/systat/ps.c
--- a/usr.bin/systat/ps.c       Wed Aug 17 13:22:33 2011 +0000
+++ b/usr.bin/systat/ps.c       Wed Aug 17 13:26:49 2011 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: ps.c,v 1.34 2009/10/21 21:12:07 rmind Exp $  */
+/*      $NetBSD: ps.c,v 1.35 2011/08/17 13:26:49 christos Exp $  */
 
 /*-
  * Copyright (c) 1999
@@ -45,7 +45,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ps.c,v 1.34 2009/10/21 21:12:07 rmind Exp $");
+__RCSID("$NetBSD: ps.c,v 1.35 2011/08/17 13:26:49 christos Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -282,11 +282,12 @@
                 * they are printed within parentheses.
                 */
                if (kp->p_flag & P_SYSTEM)
-                       fmt = "[%s]";
+                       fmt = "[]";
                else
-                       fmt = "(%s)";
+                       fmt = "()";
 
-               snprintf(commstr, sizeof(commstr), fmt, kp->p_comm);
+               snprintf(commstr, sizeof(commstr), "%c%s%c", fmt[0],
+                   kp->p_comm, fmt[1]);
        }
 
        return commstr;
@@ -324,12 +325,10 @@
                time(&now);
        if (now - u_start.tv_sec < 24 * SECSPERHOUR) {
                /* I *hate* SCCS... */
-               static char fmt[] = "%l:%" "M%p";
-               strftime(startstr, sizeof(startstr) - 1, fmt, tp);
+               strftime(startstr, sizeof(startstr) - 1, "%l:%" "M%p", tp);
        } else if (now - u_start.tv_sec < 7 * SECSPERDAY) {
                /* I *hate* SCCS... */
-               static char fmt[] = "%a%" "I%p";
-               strftime(startstr, sizeof(startstr) - 1, fmt, tp);
+               strftime(startstr, sizeof(startstr) - 1, "%a%" "I%p", tp);
        } else  
                strftime(startstr, sizeof(startstr) - 1, "%e%b%y", tp);
 



Home | Main Index | Thread Index | Old Index