Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/stdio Handle case where a 0 length template string ...



details:   https://anonhg.NetBSD.org/src/rev/1b6527333df1
branches:  trunk
changeset: 792912:1b6527333df1
user:      seanb <seanb%NetBSD.org@localhost>
date:      Tue Jan 21 19:09:48 2014 +0000

description:
Handle case where a 0 length template string or a template
of all 'X' would dereference, and maybe assign to, memory
before the template.  Simplify.

diffstat:

 lib/libc/stdio/gettemp.c |  16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diffs (41 lines):

diff -r 375b44f49421 -r 1b6527333df1 lib/libc/stdio/gettemp.c
--- a/lib/libc/stdio/gettemp.c  Tue Jan 21 19:05:10 2014 +0000
+++ b/lib/libc/stdio/gettemp.c  Tue Jan 21 19:09:48 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gettemp.c,v 1.16 2013/04/22 20:57:36 christos Exp $    */
+/*     $NetBSD: gettemp.c,v 1.17 2014/01/21 19:09:48 seanb Exp $       */
 
 /*
  * Copyright (c) 1987, 1993
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)mktemp.c   8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: gettemp.c,v 1.16 2013/04/22 20:57:36 christos Exp $");
+__RCSID("$NetBSD: gettemp.c,v 1.17 2014/01/21 19:09:48 seanb Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -89,14 +89,18 @@
                        xcnt = 0;       
 
        /* Use at least one from xtra.  Use 2 if more than 6 X's. */
-       if (*(trv - 1) == 'X')
+       if (xcnt > 0) {
                *--trv = xtra[0];
-       if (xcnt > 6 && *(trv - 1) == 'X')
+               xcnt--;
+       }
+       if (xcnt > 5) {
                *--trv = xtra[1];
+               xcnt--;
+       }
 
        /* Set remaining X's to pid digits with 0's to the left. */
-       while (*--trv == 'X') {
-               *trv = (pid % 10) + '0';
+       for (; xcnt > 0; xcnt--) {
+               *--trv = (pid % 10) + '0';
                pid /= 10;
        }
 



Home | Main Index | Thread Index | Old Index