Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/net eliminate sprintf. use snprintf.



details:   https://anonhg.NetBSD.org/src/rev/9aca668a0e02
branches:  trunk
changeset: 535361:9aca668a0e02
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Aug 16 11:45:55 2002 +0000

description:
eliminate sprintf.  use snprintf.
XXX loc_ntoa should be changed to take additional size_t as arg

diffstat:

 lib/libc/net/res_debug.c |  19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

diffs (81 lines):

diff -r 1292de12b70c -r 9aca668a0e02 lib/libc/net/res_debug.c
--- a/lib/libc/net/res_debug.c  Fri Aug 16 11:30:28 2002 +0000
+++ b/lib/libc/net/res_debug.c  Fri Aug 16 11:45:55 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: res_debug.c,v 1.32 2002/06/27 10:22:10 itojun Exp $    */
+/*     $NetBSD: res_debug.c,v 1.33 2002/08/16 11:45:55 itojun Exp $    */
 
 /*-
  * Copyright (c) 1985, 1990, 1993
@@ -81,7 +81,7 @@
 static char sccsid[] = "@(#)res_debug.c        8.1 (Berkeley) 6/4/93";
 static char rcsid[] = "Id: res_debug.c,v 8.20 1997/06/01 20:34:37 vixie Exp ";
 #else
-__RCSID("$NetBSD: res_debug.c,v 1.32 2002/06/27 10:22:10 itojun Exp $");
+__RCSID("$NetBSD: res_debug.c,v 1.33 2002/08/16 11:45:55 itojun Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -1011,7 +1011,7 @@
                }
        }
 
-       sprintf (unname, "%d", number);
+       snprintf(unname, sizeof(unname), "%d", number);
        if (success)
                *success = 0;
        return (unname);
@@ -1036,7 +1036,7 @@
                        return (syms->humanname);
                }
        }
-       sprintf(unname, "%d", number);
+       snprintf(unname, sizeof(unname), "%d", number);
        if (success)
                *success = 0;
        return (unname);
@@ -1179,7 +1179,7 @@
 
        val = mantissa * poweroften[exponent];
 
-       (void) sprintf(retbuf, "%ld.%.2ld", val/100, val%100);
+       (void) snprintf(retbuf, sizeof(retbuf), "%ld.%.2ld", val/100, val%100);
        return (retbuf);
 }
 
@@ -1478,7 +1478,7 @@
        versionval = *cp++;
 
        if (versionval) {
-               sprintf(ascii, "; error: unknown LOC RR version");
+               snprintf(ascii, 255, "; error: unknown LOC RR version"); /*XXX*/
                return (ascii);
        }
 
@@ -1540,7 +1540,8 @@
        if ((vpstr = strdup(precsize_ntoa((u_int32_t)vpval))) == NULL)
                vpstr = error;
 
-       sprintf(ascii,
+       /* XXX */
+       snprintf(ascii, 255,
              "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm",
                latdeg, latmin, latsec, latsecfrac, northsouth,
                longdeg, longmin, longsec, longsecfrac, eastwest,
@@ -1595,14 +1596,14 @@
 __p_secstodate (secs)
        unsigned long secs;
 {
-       static char output[15];         /* YYYYMMDDHHMMSS and null */
+       static char output[15];         /* YYYYMMDDHHMMSS and \0 */
        time_t clk = secs;
        struct tm tim;
        
        (void)gmtime_r(&clk, &tim);
        tim.tm_year += 1900;
        tim.tm_mon += 1;
-       sprintf(output, "%04d%02d%02d%02d%02d%02d",
+       snprintf(output, sizeof(output), "%04d%02d%02d%02d%02d%02d",
                tim.tm_year, tim.tm_mon, tim.tm_mday,
                tim.tm_hour, tim.tm_min, tim.tm_sec);
        return (output);



Home | Main Index | Thread Index | Old Index