Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint use asprintf().



details:   https://anonhg.NetBSD.org/src/rev/5bfc2c79a25b
branches:  trunk
changeset: 744666:5bfc2c79a25b
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Feb 10 04:54:01 2020 +0000

description:
use asprintf().

diffstat:

 usr.bin/xlint/common/externs.h |   3 ++-
 usr.bin/xlint/common/mem.c     |  18 ++++++++++++++++--
 usr.bin/xlint/xlint/xlint.c    |  13 +++++--------
 3 files changed, 23 insertions(+), 11 deletions(-)

diffs (104 lines):

diff -r cdff57348549 -r 5bfc2c79a25b usr.bin/xlint/common/externs.h
--- a/usr.bin/xlint/common/externs.h    Mon Feb 10 03:23:29 2020 +0000
+++ b/usr.bin/xlint/common/externs.h    Mon Feb 10 04:54:01 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs.h,v 1.6 2016/08/19 10:18:11 christos Exp $     */
+/*     $NetBSD: externs.h,v 1.7 2020/02/10 04:54:01 christos Exp $     */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -57,6 +57,7 @@
 extern char    *xstrdup(const char *);
 extern void    nomem(void);
 extern void    *xmapalloc(size_t);
+extern  void   xasprintf(char **, const char *, ...) __printflike(2, 3);
 
 /*
  * emit.c
diff -r cdff57348549 -r 5bfc2c79a25b usr.bin/xlint/common/mem.c
--- a/usr.bin/xlint/common/mem.c        Mon Feb 10 03:23:29 2020 +0000
+++ b/usr.bin/xlint/common/mem.c        Mon Feb 10 04:54:01 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mem.c,v 1.7 2004/06/20 22:20:16 jmc Exp $      */
+/*     $NetBSD: mem.c,v 1.8 2020/02/10 04:54:01 christos Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,12 +37,13 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: mem.c,v 1.7 2004/06/20 22:20:16 jmc Exp $");
+__RCSID("$NetBSD: mem.c,v 1.8 2020/02/10 04:54:01 christos Exp $");
 #endif
 
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/mman.h>
+#include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -98,6 +99,19 @@
        errx(1, "virtual memory exhausted");
 }
 
+void
+xasprintf(char **buf, const char *fmt, ...)
+{
+       int e;
+       va_list ap;
+
+       va_start(ap, fmt);
+       e = vasprintf(buf, fmt, ap);
+       va_end(ap);
+       if (e < 0)
+               nomem();
+}
+
 #if defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
 #define        MAP_ANON        MAP_ANONYMOUS
 #endif
diff -r cdff57348549 -r 5bfc2c79a25b usr.bin/xlint/xlint/xlint.c
--- a/usr.bin/xlint/xlint/xlint.c       Mon Feb 10 03:23:29 2020 +0000
+++ b/usr.bin/xlint/xlint/xlint.c       Mon Feb 10 04:54:01 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xlint.c,v 1.48 2020/02/09 08:10:25 fox Exp $ */
+/* $NetBSD: xlint.c,v 1.49 2020/02/10 04:54:01 christos Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: xlint.c,v 1.48 2020/02/09 08:10:25 fox Exp $");
+__RCSID("$NetBSD: xlint.c,v 1.49 2020/02/10 04:54:01 christos Exp $");
 #endif
 
 #include <sys/param.h>
@@ -613,7 +613,7 @@
        const   char *bn, *suff;
        char    **args, *ofn, *pathname;
        const char *CC;
-       size_t  buff_size, len;
+       size_t  len;
        int is_stdin;
        int     fd;
 
@@ -648,13 +648,10 @@
                        warnx("-i not supported without -o for standard input");
                        return;
                }
-               buff_size = strlen(bn) + (bn == suff ? 4 : 2);
-               ofn = xmalloc(buff_size);
                len = bn == suff ? strlen(bn) : (size_t)((suff - 1) - bn);
-               (void)snprintf(ofn, buff_size, "%.*s.ln", (int)len, bn);
+               xasprintf(&ofn, "%.*s.ln", (int)len, bn);
        } else {
-               ofn = xmalloc(strlen(tmpdir) + sizeof ("lint1.XXXXXX"));
-               (void)sprintf(ofn, "%slint1.XXXXXX", tmpdir);
+               xasprintf(&ofn, "%slint1.XXXXXX", tmpdir);
                fd = mkstemp(ofn);
                if (fd == -1) {
                        warn("can't make temp");



Home | Main Index | Thread Index | Old Index