Source-Changes-HG archive

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

[src/trunk]: src/sys/arch kill sprintf



details:   https://anonhg.NetBSD.org/src/rev/a9dd7d7ad1f9
branches:  trunk
changeset: 794829:a9dd7d7ad1f9
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Mar 26 08:04:19 2014 +0000

description:
kill sprintf

diffstat:

 sys/arch/alpha/stand/setnetbootinfo/setnetbootinfo.c |  8 +++++---
 sys/arch/alpha/tc/ioasic.c                           |  9 +++++----
 sys/arch/alpha/tc/tc_3000_300.c                      |  9 +++++----
 sys/arch/alpha/tc/tc_3000_500.c                      |  9 +++++----
 sys/arch/alpha/tlsb/tlsb.c                           |  8 ++++----
 sys/arch/x86/x86/cpu_ucode_intel.c                   |  7 ++++---
 sys/arch/x86/x86/platform.c                          |  6 +++---
 7 files changed, 31 insertions(+), 25 deletions(-)

diffs (213 lines):

diff -r 2b68eacc3da7 -r a9dd7d7ad1f9 sys/arch/alpha/stand/setnetbootinfo/setnetbootinfo.c
--- a/sys/arch/alpha/stand/setnetbootinfo/setnetbootinfo.c      Wed Mar 26 08:02:38 2014 +0000
+++ b/sys/arch/alpha/stand/setnetbootinfo/setnetbootinfo.c      Wed Mar 26 08:04:19 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: setnetbootinfo.c,v 1.13 2009/03/14 21:04:03 dsl Exp $ */
+/* $NetBSD: setnetbootinfo.c,v 1.14 2014/03/26 08:09:06 christos Exp $ */
 
 /*
  * Copyright (c) 1997 Christopher G. Demetriou
@@ -139,10 +139,12 @@
                outfilename = outfile;
        else {
                /* name + 12 for enet addr + '.' before enet addr + NUL */
-               outfilename = malloc(strlen(netboot) + 14);
+               size_t len = strlen(netboot) + 14;
+               outfilename = malloc(len);
                if (outfilename == NULL)
                        err(1, "malloc of output file name failed");
-               sprintf(outfilename, "%s.%02x%02x%02x%02x%02x%02x", netboot,
+               snprintf(outfilename, len,
+                   "%s.%02x%02x%02x%02x%02x%02x", netboot,
                    ether_addr->ether_addr_octet[0],
                    ether_addr->ether_addr_octet[1],
                    ether_addr->ether_addr_octet[2],
diff -r 2b68eacc3da7 -r a9dd7d7ad1f9 sys/arch/alpha/tc/ioasic.c
--- a/sys/arch/alpha/tc/ioasic.c        Wed Mar 26 08:02:38 2014 +0000
+++ b/sys/arch/alpha/tc/ioasic.c        Wed Mar 26 08:04:19 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ioasic.c,v 1.45 2012/02/06 02:14:16 matt Exp $ */
+/* $NetBSD: ioasic.c,v 1.46 2014/03/26 08:09:06 christos Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: ioasic.c,v 1.45 2012/02/06 02:14:16 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ioasic.c,v 1.46 2014/03/26 08:09:06 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -192,13 +192,14 @@
         */
        pevcnt = tc_intr_evcnt(parent, ta->ta_cookie);
        for (i = 0; i < IOASIC_NCOOKIES; i++) {
+               static const size_t len = 12;
                ioasicintrs[i].iai_func = ioasic_intrnull;
                ioasicintrs[i].iai_arg = (void *)i;
 
-               cp = malloc(12, M_DEVBUF, M_NOWAIT);
+               cp = malloc(len, M_DEVBUF, M_NOWAIT);
                if (cp == NULL)
                        panic("ioasicattach");
-               sprintf(cp, "slot %lu", i);
+               snprintf(cp, len, "slot %lu", i);
                evcnt_attach_dynamic(&ioasicintrs[i].iai_evcnt,
                    EVCNT_TYPE_INTR, pevcnt, device_xname(self), cp);
        }
diff -r 2b68eacc3da7 -r a9dd7d7ad1f9 sys/arch/alpha/tc/tc_3000_300.c
--- a/sys/arch/alpha/tc/tc_3000_300.c   Wed Mar 26 08:02:38 2014 +0000
+++ b/sys/arch/alpha/tc/tc_3000_300.c   Wed Mar 26 08:04:19 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tc_3000_300.c,v 1.32 2012/02/06 02:14:16 matt Exp $ */
+/* $NetBSD: tc_3000_300.c,v 1.33 2014/03/26 08:09:06 christos Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: tc_3000_300.c,v 1.32 2012/02/06 02:14:16 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tc_3000_300.c,v 1.33 2014/03/26 08:09:06 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -107,13 +107,14 @@
         * Set up interrupt handlers.
         */
        for (i = 0; i < TC_3000_300_NCOOKIES; i++) {
+               static const size_t len = 12;
                tc_3000_300_intr[i].tci_func = tc_3000_300_intrnull;
                tc_3000_300_intr[i].tci_arg = (void *)i;
                
-               cp = malloc(12, M_DEVBUF, M_NOWAIT);
+               cp = malloc(len, M_DEVBUF, M_NOWAIT);
                if (cp == NULL)
                        panic("tc_3000_300_intr_setup");
-               sprintf(cp, "slot %lu", i);
+               snprintf(cp, len, "slot %lu", i);
                evcnt_attach_dynamic(&tc_3000_300_intr[i].tci_evcnt,
                    EVCNT_TYPE_INTR, NULL, "tc", cp);
        }
diff -r 2b68eacc3da7 -r a9dd7d7ad1f9 sys/arch/alpha/tc/tc_3000_500.c
--- a/sys/arch/alpha/tc/tc_3000_500.c   Wed Mar 26 08:02:38 2014 +0000
+++ b/sys/arch/alpha/tc/tc_3000_500.c   Wed Mar 26 08:04:19 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tc_3000_500.c,v 1.31 2012/02/06 02:14:16 matt Exp $ */
+/* $NetBSD: tc_3000_500.c,v 1.32 2014/03/26 08:09:06 christos Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: tc_3000_500.c,v 1.31 2012/02/06 02:14:16 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tc_3000_500.c,v 1.32 2014/03/26 08:09:06 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -131,13 +131,14 @@
         * Set up interrupt handlers.
         */
        for (i = 0; i < TC_3000_500_NCOOKIES; i++) {
+               static const size_t len = 12;
                tc_3000_500_intr[i].tci_func = tc_3000_500_intrnull;
                tc_3000_500_intr[i].tci_arg = (void *)i;
 
-               cp = malloc(12, M_DEVBUF, M_NOWAIT);
+               cp = malloc(len, M_DEVBUF, M_NOWAIT);
                if (cp == NULL)
                        panic("tc_3000_500_intr_setup");
-               sprintf(cp, "slot %lu", i);
+               snprintf(cp, len, "slot %lu", i);
                evcnt_attach_dynamic(&tc_3000_500_intr[i].tci_evcnt,
                    EVCNT_TYPE_INTR, NULL, "tc", cp);
        }
diff -r 2b68eacc3da7 -r a9dd7d7ad1f9 sys/arch/alpha/tlsb/tlsb.c
--- a/sys/arch/alpha/tlsb/tlsb.c        Wed Mar 26 08:02:38 2014 +0000
+++ b/sys/arch/alpha/tlsb/tlsb.c        Wed Mar 26 08:04:19 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tlsb.c,v 1.37 2012/02/06 02:14:16 matt Exp $ */
+/* $NetBSD: tlsb.c,v 1.38 2014/03/26 08:09:06 christos Exp $ */
 /*
  * Copyright (c) 1997 by Matthew Jacob
  * NASA AMES Research Center.
@@ -39,7 +39,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: tlsb.c,v 1.37 2012/02/06 02:14:16 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tlsb.c,v 1.38 2014/03/26 08:09:06 christos Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -260,8 +260,8 @@
                return ("Dual CPU, 16MB cache");
 
        default:
-               memset(tlsb_line, 0, sizeof(tlsb_line));
-               sprintf(tlsb_line, "unknown, dtype 0x%x", dtype);
+               snprintf(tlsb_line, sizeof(tlsb_line), "unknown, dtype 0x%x",
+                   dtype);
                return (tlsb_line);
        }
        /* NOTREACHED */
diff -r 2b68eacc3da7 -r a9dd7d7ad1f9 sys/arch/x86/x86/cpu_ucode_intel.c
--- a/sys/arch/x86/x86/cpu_ucode_intel.c        Wed Mar 26 08:02:38 2014 +0000
+++ b/sys/arch/x86/x86/cpu_ucode_intel.c        Wed Mar 26 08:04:19 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode_intel.c,v 1.4 2013/11/15 08:47:55 msaitoh Exp $ */
+/* $NetBSD: cpu_ucode_intel.c,v 1.5 2014/03/26 08:04:19 christos Exp $ */
 /*
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.4 2013/11/15 08:47:55 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.5 2014/03/26 08:04:19 christos Exp $");
 
 #include "opt_xen.h"
 #include "opt_cpu_ucode.h"
@@ -102,7 +102,8 @@
                return EOPNOTSUPP;
 
        intel_getcurrentucode(&ucodeversion, &platformid);
-       sprintf(cpuspec, "%08x-%d", cpu_signature, platformid);
+       snprintf(cpuspec, sizeof(cpuspec), "%08x-%d", cpu_signature,
+           platformid);
 
        return firmware_open(fw_path, cpuspec, fwh);
 }
diff -r 2b68eacc3da7 -r a9dd7d7ad1f9 sys/arch/x86/x86/platform.c
--- a/sys/arch/x86/x86/platform.c       Wed Mar 26 08:02:38 2014 +0000
+++ b/sys/arch/x86/x86/platform.c       Wed Mar 26 08:04:19 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: platform.c,v 1.14 2012/12/08 12:36:31 kiyohara Exp $ */
+/* $NetBSD: platform.c,v 1.15 2014/03/26 08:04:19 christos Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
 #include "isa.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: platform.c,v 1.14 2012/12/08 12:36:31 kiyohara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: platform.c,v 1.15 2014/03/26 08:04:19 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -242,7 +242,7 @@
                year += 2000;
        else if (year < 100)
                year += 1900;
-       sprintf(datestr, "%04u%02u%02u", year, month, day);
+       snprintf(datestr, sizeof(datestr), "%04u%02u%02u", year, month, day);
        pmf_set_platform(key, datestr);
        platform_create_sysctl(key);
 }



Home | Main Index | Thread Index | Old Index