Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/libc/ssp allocate the buffer at the same function ...



details:   https://anonhg.NetBSD.org/src/rev/130eed30dbbb
branches:  trunk
changeset: 760145:130eed30dbbb
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Dec 28 16:18:46 2010 +0000

description:
allocate the buffer at the same function level as the compiler so that
the compiler knows to emit the right _chk call.

diffstat:

 tests/lib/libc/ssp/h_vsnprintf.c |  18 +++++++++---------
 tests/lib/libc/ssp/h_vsprintf.c  |  16 ++++++++--------
 2 files changed, 17 insertions(+), 17 deletions(-)

diffs (91 lines):

diff -r 18dca52bf91b -r 130eed30dbbb tests/lib/libc/ssp/h_vsnprintf.c
--- a/tests/lib/libc/ssp/h_vsnprintf.c  Tue Dec 28 15:28:31 2010 +0000
+++ b/tests/lib/libc/ssp/h_vsnprintf.c  Tue Dec 28 16:18:46 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: h_vsnprintf.c,v 1.1 2010/12/27 02:04:19 pgoyette Exp $ */
+/* $NetBSD: h_vsnprintf.c,v 1.2 2010/12/28 16:18:46 christos Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,29 +29,29 @@
 #include <sys/cdefs.h>
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: h_vsnprintf.c,v 1.1 2010/12/27 02:04:19 pgoyette Exp $");
+__RCSID("$NetBSD: h_vsnprintf.c,v 1.2 2010/12/28 16:18:46 christos Exp $");
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
 
-static void wrap(char *str, size_t, const char *, ...);
+void wrap(size_t, const char *, ...);
 
-static void
-wrap(char *str, size_t len, const char *fmt, ...)
+void
+wrap(size_t len, const char *fmt, ...)
 {
+       char b[10];
        va_list ap;
        va_start(ap, fmt);
-       (void)vsnprintf(str, len, fmt, ap);
+       (void)vsnprintf(b, len, fmt, ap);
+       (void)printf("%s\n", b);
        va_end(ap);
 }
 
 int
 main(int argc, char *argv[])
 {
-       char b[10];
        size_t len = atoi(argv[1]);
-       wrap(b, len, "%s", "012345678910");
-       (void)printf("%s\n", b);
+       wrap(len, "%s", "012345678901234567890");
        return 0;
 }
diff -r 18dca52bf91b -r 130eed30dbbb tests/lib/libc/ssp/h_vsprintf.c
--- a/tests/lib/libc/ssp/h_vsprintf.c   Tue Dec 28 15:28:31 2010 +0000
+++ b/tests/lib/libc/ssp/h_vsprintf.c   Tue Dec 28 16:18:46 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: h_vsprintf.c,v 1.1 2010/12/27 02:04:19 pgoyette Exp $ */
+/* $NetBSD: h_vsprintf.c,v 1.2 2010/12/28 16:18:46 christos Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,27 +29,27 @@
 #include <sys/cdefs.h>
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: h_vsprintf.c,v 1.1 2010/12/27 02:04:19 pgoyette Exp $");
+__RCSID("$NetBSD: h_vsprintf.c,v 1.2 2010/12/28 16:18:46 christos Exp $");
 
 #include <stdio.h>
 #include <stdarg.h>
 
-static void wrap(char *str, const char *, ...);
+static void wrap(const char *, ...);
 
 static void
-wrap(char *str, const char *fmt, ...)
+wrap(const char *fmt, ...)
 {
+       char b[10];
        va_list ap;
        va_start(ap, fmt);
-       (void)vsprintf(str, fmt, ap);
+       (void)vsprintf(b, fmt, ap);
+       (void)printf("%s\n", b);
        va_end(ap);
 }
 
 int
 main(int argc, char *argv[])
 {
-       char b[10];
-       wrap(b, "%s", argv[1]);
-       (void)printf("%s\n", b);
+       wrap("%s", argv[1]);
        return 0;
 }



Home | Main Index | Thread Index | Old Index