Source-Changes-HG archive

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

[src/trunk]: src/sys sprintf -> snprintf



details:   https://anonhg.NetBSD.org/src/rev/3efb04337499
branches:  trunk
changeset: 565860:3efb04337499
user:      itojun <itojun%NetBSD.org@localhost>
date:      Thu Apr 22 00:31:00 2004 +0000

description:
sprintf -> snprintf

diffstat:

 sys/arch/i386/eisa/eisa_machdep.c  |  10 +++---
 sys/arch/i386/i386/autoconf.c      |   9 +++--
 sys/arch/i386/i386/identcpu.c      |   6 +-
 sys/miscfs/procfs/procfs_cmdline.c |  10 +----
 sys/miscfs/procfs/procfs_linux.c   |  63 ++++++++++---------------------------
 sys/miscfs/procfs/procfs_status.c  |  59 ++++++++++++++---------------------
 sys/miscfs/procfs/procfs_vnops.c   |  18 +++++-----
 7 files changed, 67 insertions(+), 108 deletions(-)

diffs (truncated from 439 to 300 lines):

diff -r 724c0e4eb37c -r 3efb04337499 sys/arch/i386/eisa/eisa_machdep.c
--- a/sys/arch/i386/eisa/eisa_machdep.c Thu Apr 22 00:17:10 2004 +0000
+++ b/sys/arch/i386/eisa/eisa_machdep.c Thu Apr 22 00:31:00 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eisa_machdep.c,v 1.21 2003/10/30 21:19:54 fvdl Exp $   */
+/*     $NetBSD: eisa_machdep.c,v 1.22 2004/04/22 00:34:52 itojun Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -72,7 +72,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: eisa_machdep.c,v 1.21 2003/10/30 21:19:54 fvdl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: eisa_machdep.c,v 1.22 2004/04/22 00:34:52 itojun Exp $");
 
 #include "ioapic.h"
 
@@ -192,14 +192,14 @@
 
 #if NIOAPIC > 0
        if (ih & APIC_INT_VIA_APIC)
-               sprintf(irqstr, "apic %d int %d (irq %d)",
+               snprintf(irqstr, sizeof(irqstr), "apic %d int %d (irq %d)",
                    APIC_IRQ_APIC(ih),
                    APIC_IRQ_PIN(ih),
                    ih&0xff);
        else
-               sprintf(irqstr, "irq %d", ih&0xff);
+               snprintf(irqstr, sizeof(irqstr), "irq %d", ih&0xff);
 #else
-       sprintf(irqstr, "irq %d", ih);
+       snprintf(irqstr, sizeof(irqstr), "irq %d", ih);
 #endif
        return (irqstr);
        
diff -r 724c0e4eb37c -r 3efb04337499 sys/arch/i386/i386/autoconf.c
--- a/sys/arch/i386/i386/autoconf.c     Thu Apr 22 00:17:10 2004 +0000
+++ b/sys/arch/i386/i386/autoconf.c     Thu Apr 22 00:31:00 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: autoconf.c,v 1.75 2003/12/30 12:33:22 pk Exp $ */
+/*     $NetBSD: autoconf.c,v 1.76 2004/04/22 00:34:52 itojun Exp $     */
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -44,7 +44,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.75 2003/12/30 12:33:22 pk Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.76 2004/04/22 00:34:52 itojun Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_multiprocessor.h"
@@ -240,7 +240,8 @@
 #endif
                if (is_valid_disk(dv)) {
                        n++;
-                       sprintf(i386_alldisks->dl_nativedisks[n].ni_devname,
+                       snprintf(i386_alldisks->dl_nativedisks[n].ni_devname,
+                           sizeof(i386_alldisks->dl_nativedisks[n].ni_devname),
                            "%s%d", dv->dv_cfdata->cf_name,
                            dv->dv_unit);
 
@@ -476,7 +477,7 @@
        part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
        unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK;
 
-       sprintf(buf, "%s%d", name, unit);
+       snprintf(buf, sizeof(buf), "%s%d", name, unit);
        for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
                if (strcmp(buf, dv->dv_xname) == 0) {
                        booted_device = dv;
diff -r 724c0e4eb37c -r 3efb04337499 sys/arch/i386/i386/identcpu.c
--- a/sys/arch/i386/i386/identcpu.c     Thu Apr 22 00:17:10 2004 +0000
+++ b/sys/arch/i386/i386/identcpu.c     Thu Apr 22 00:31:00 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: identcpu.c,v 1.11 2004/04/05 02:09:41 mrg Exp $        */
+/*     $NetBSD: identcpu.c,v 1.12 2004/04/22 00:34:52 itojun Exp $     */
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.11 2004/04/05 02:09:41 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.12 2004/04/22 00:34:52 itojun Exp $");
 
 #include "opt_cputype.h"
 
@@ -821,7 +821,7 @@
        for (i = 1; i < sizeof(amd_brand) / sizeof(amd_brand[0]); i++)
                if ((p = strstr((char *)brand, amd_brand[i])) != NULL) {
                        ci->ci_brand_id = i;
-                       strcpy(amd_brand_name, p);
+                       strlcpy(amd_brand_name, p, sizeof(amd_brand_name));
                        break;
                }
 }
diff -r 724c0e4eb37c -r 3efb04337499 sys/miscfs/procfs/procfs_cmdline.c
--- a/sys/miscfs/procfs/procfs_cmdline.c        Thu Apr 22 00:17:10 2004 +0000
+++ b/sys/miscfs/procfs/procfs_cmdline.c        Thu Apr 22 00:31:00 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_cmdline.c,v 1.17 2003/06/29 22:31:45 fvdl Exp $ */
+/*     $NetBSD: procfs_cmdline.c,v 1.18 2004/04/22 00:31:00 itojun Exp $       */
 
 /*
  * Copyright (c) 1999 Jaromir Dolecek <dolecek%ics.muni.cz@localhost>
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_cmdline.c,v 1.17 2003/06/29 22:31:45 fvdl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_cmdline.c,v 1.18 2004/04/22 00:31:00 itojun Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -85,11 +85,7 @@
         */
        if (P_ZOMBIE(p) || (p->p_flag & P_SYSTEM) != 0) {
                len = snprintf(arg, PAGE_SIZE, "(%s)", p->p_comm);
-               xlen = len - uio->uio_offset;
-               if (xlen <= 0) 
-                       error = 0;
-               else
-                       error = uiomove(arg, xlen, uio);
+               error = uiomove_frombuf(arg, len, uio);
 
                free(arg, M_TEMP);
                return (error);
diff -r 724c0e4eb37c -r 3efb04337499 sys/miscfs/procfs/procfs_linux.c
--- a/sys/miscfs/procfs/procfs_linux.c  Thu Apr 22 00:17:10 2004 +0000
+++ b/sys/miscfs/procfs/procfs_linux.c  Thu Apr 22 00:31:00 2004 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: procfs_linux.c,v 1.15 2003/10/30 14:51:01 christos Exp $      */
+/*      $NetBSD: procfs_linux.c,v 1.16 2004/04/22 00:31:00 itojun Exp $      */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.15 2003/10/30 14:51:01 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.16 2004/04/22 00:31:00 itojun Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -68,8 +68,8 @@
 procfs_domeminfo(struct proc *curp, struct proc *p, struct pfsnode *pfs,
                 struct uio *uio)
 {
-       char buf[512], *cp;
-       int len, error;
+       char buf[512];
+       int len;
 
        len = snprintf(buf, sizeof buf,
                "        total:    used:    free:  shared: buffers: cached:\n"
@@ -102,14 +102,7 @@
        if (len == 0)
                return 0;
 
-       len -= uio->uio_offset;
-       cp = buf + uio->uio_offset;
-       len = imin(len, uio->uio_resid);
-       if (len <= 0)
-               error = 0;
-       else
-               error = uiomove(cp, len, uio);
-       return error;
+       return (uiomove_frombuf(buf, len, uio));
 }
 
 /*
@@ -120,8 +113,8 @@
 procfs_do_pid_stat(struct proc *p, struct lwp *l, struct pfsnode *pfs,
                 struct uio *uio)
 {
-       char buf[512], *cp;
-       int len, error;
+       char buf[512];
+       int len;
        struct tty *tty = p->p_session->s_ttyp;
        struct rusage *ru = &p->p_stats->p_ru;
        struct rusage *cru = &p->p_stats->p_cru;
@@ -214,22 +207,15 @@
        if (len == 0)
                return 0;
 
-       len -= uio->uio_offset;
-       cp = buf + uio->uio_offset;
-       len = imin(len, uio->uio_resid);
-       if (len <= 0)
-               error = 0;
-       else
-               error = uiomove(cp, len, uio);
-       return error;
+       return (uiomove_frombuf(buf, len, uio));
 }
 
 int
 procfs_docpuinfo(struct proc *curp, struct proc *p, struct pfsnode *pfs,
                 struct uio *uio)
 {
-       char buf[512], *cp;
-       int len, error;
+       char buf[512];
+       int len;
 
        len = sizeof buf;
        if (procfs_getcpuinfstr(buf, &len) < 0)
@@ -238,40 +224,27 @@
        if (len == 0)
                return 0;
 
-       len -= uio->uio_offset;
-       cp = buf + uio->uio_offset;
-       len = imin(len, uio->uio_resid);
-       if (len <= 0)
-               error = 0;
-       else
-               error = uiomove(cp, len, uio);
-       return error;
+       return (uiomove_frombuf(buf, len, uio));
 }
 
 int
 procfs_douptime(struct proc *curp, struct proc *p, struct pfsnode *pfs,
                 struct uio *uio)
 {
-       char buf[512], *cp;
-       int len, error;
+       char buf[512];
+       int len;
        struct timeval runtime;
        u_int64_t idle;
 
        timersub(&curcpu()->ci_schedstate.spc_runtime, &boottime, &runtime);
        idle = curcpu()->ci_schedstate.spc_cp_time[CP_IDLE];
-       len = sprintf(buf, "%lu.%02lu %" PRIu64 ".%02" PRIu64 "\n",
-                     runtime.tv_sec, runtime.tv_usec / 10000,
-                     idle / hz, (((idle % hz) * 100) / hz) % 100);
+       len = snprintf(buf, sizeof(buf),
+           "%lu.%02lu %" PRIu64 ".%02" PRIu64 "\n",
+           runtime.tv_sec, runtime.tv_usec / 10000,
+           idle / hz, (((idle % hz) * 100) / hz) % 100);
 
        if (len == 0)
                return 0;
 
-       len -= uio->uio_offset;
-       cp = buf + uio->uio_offset;
-       len = imin(len, uio->uio_resid);
-       if (len <= 0)
-               error = 0;
-       else
-               error = uiomove(cp, len, uio);
-       return error;
+       return (uiomove_frombuf(buf, len, uio));
 }
diff -r 724c0e4eb37c -r 3efb04337499 sys/miscfs/procfs/procfs_status.c
--- a/sys/miscfs/procfs/procfs_status.c Thu Apr 22 00:17:10 2004 +0000
+++ b/sys/miscfs/procfs/procfs_status.c Thu Apr 22 00:31:00 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_status.c,v 1.22 2003/08/07 16:32:42 agc Exp $   */
+/*     $NetBSD: procfs_status.c,v 1.23 2004/04/22 00:31:00 itojun Exp $        */
 
 /*
  * Copyright (c) 1993
@@ -72,7 +72,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_status.c,v 1.22 2003/08/07 16:32:42 agc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_status.c,v 1.23 2004/04/22 00:31:00 itojun Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -101,8 +101,6 @@
        char *sep;
        int pid, ppid, pgid, sid;
        u_int i;
-       int xlen;
-       int error;
        char psbuf[256+MAXHOSTNAMELEN];         /* XXX - conservative */
 
        if (uio->uio_rw != UIO_READ)
@@ -120,63 +118,54 @@
        memcpy(ps, p->p_comm, MAXCOMLEN);
        ps[MAXCOMLEN] = '\0';
        ps += strlen(ps);
-       ps += sprintf(ps, " %d %d %d %d ", pid, ppid, pgid, sid);
+       ps += snprintf(ps, sizeof(psbuf) - (ps - psbuf), " %d %d %d %d ",
+           pid, ppid, pgid, sid);
 
        if ((p->p_flag&P_CONTROLT) && (tp = sess->s_ttyp))
-               ps += sprintf(ps, "%d,%d ", major(tp->t_dev),
-                   minor(tp->t_dev));



Home | Main Index | Thread Index | Old Index