Source-Changes-HG archive

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

[src/trunk]: src/lib/libwrap Provide an extra argument to store the returned ...



details:   https://anonhg.NetBSD.org/src/rev/e7df688f3573
branches:  trunk
changeset: 447474:e7df688f3573
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Jan 12 19:08:24 2019 +0000

description:
Provide an extra argument to store the returned pointer so we can use
the function directly as the return format (before assigning it to a
variable) to appease clang.

diffstat:

 lib/libwrap/diag.c    |  19 +++++++++----------
 lib/libwrap/expandm.c |  16 +++++++++++-----
 lib/libwrap/expandm.h |   5 +++--
 3 files changed, 23 insertions(+), 17 deletions(-)

diffs (124 lines):

diff -r 6795fc6d183b -r e7df688f3573 lib/libwrap/diag.c
--- a/lib/libwrap/diag.c        Sat Jan 12 18:58:10 2019 +0000
+++ b/lib/libwrap/diag.c        Sat Jan 12 19:08:24 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: diag.c,v 1.16 2019/01/11 20:37:30 christos Exp $       */
+/*     $NetBSD: diag.c,v 1.17 2019/01/12 19:08:24 christos Exp $       */
 
  /*
   * Routines to report various classes of problems. Each report is decorated
@@ -16,7 +16,7 @@
 #if 0
 static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
 #else
-__RCSID("$NetBSD: diag.c,v 1.16 2019/01/11 20:37:30 christos Exp $");
+__RCSID("$NetBSD: diag.c,v 1.17 2019/01/12 19:08:24 christos Exp $");
 #endif
 #endif
 
@@ -46,22 +46,21 @@
 static void
 tcpd_diag(int severity, const char *tag, const char *fmt, va_list ap)
 {
-    char *buf2, *buf = expandm(fmt, NULL);
+    char *buf, *bufx;
 
-    if (vasprintf(&buf2, buf, ap) == -1)
-       buf2 = buf;
+    if (vasprintf(&buf, expandm(fmt, NULL, &bufx), ap) == -1)
+       buf = __UNCONST(fmt);
+    free(bufx);
 
     /* contruct the tag for the log entry */
     if (tcpd_context.file)
        syslog(severity, "%s: %s, line %d: %s",
-           tag, tcpd_context.file, tcpd_context.line, buf2);
+           tag, tcpd_context.file, tcpd_context.line, buf);
     else
-       syslog(severity, "%s: %s", tag, buf2);
+       syslog(severity, "%s: %s", tag, buf);
 
     if (buf != fmt)
-        free(buf);
-    if (buf2 != buf)
-       free(buf2);
+       free(buf);
 }
 
 /* tcpd_warn - report problem of some sort and proceed */
diff -r 6795fc6d183b -r e7df688f3573 lib/libwrap/expandm.c
--- a/lib/libwrap/expandm.c     Sat Jan 12 18:58:10 2019 +0000
+++ b/lib/libwrap/expandm.c     Sat Jan 12 19:08:24 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: expandm.c,v 1.1 2019/01/11 20:37:30 christos Exp $     */
+/*     $NetBSD: expandm.c,v 1.2 2019/01/12 19:08:24 christos Exp $     */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: expandm.c,v 1.1 2019/01/11 20:37:30 christos Exp $");
+__RCSID("$NetBSD: expandm.c,v 1.2 2019/01/12 19:08:24 christos Exp $");
 
 #include <stdio.h>
 #include <string.h>
@@ -39,13 +39,15 @@
 #include "expandm.h"
 
 char * __attribute__((__format_arg__(1)))
-expandm(const char *fmt, const char *sf)
+expandm(const char *fmt, const char *sf, char **rbuf)
 {
        const char *e = strerror(errno);
        char *buf, *m, *nbuf;
        const char *ptr;
 
-       for (ptr = fmt, buf = NULL; (m = strstr(ptr, "%m")); ptr = m + 2) {
+       for (ptr = fmt, buf = NULL; (m = strstr(ptr, "%m")) != NULL;
+           ptr = m + 2)
+       {
                size_t cnt = 0;
                for (char *p = m; p >= ptr && *p == '%'; p--)
                        cnt++;
@@ -60,9 +62,13 @@
                goto out;
 
        free(buf);
+       if (rbuf)
+               *rbuf = buf;
        return nbuf;
 out:
        free(buf);
+       if (rbuf)
+               *rbuf = NULL;
        return __UNCONST(fmt);
 }
 
@@ -71,7 +77,7 @@
 main(int argc, char *argv[])
 {
        errno = ERANGE;
-       printf("%s\n", expandm(argv[1]));
+       printf("%s\n", expandm(argv[1], "", NULL));
        return 0;
 }
 #endif
diff -r 6795fc6d183b -r e7df688f3573 lib/libwrap/expandm.h
--- a/lib/libwrap/expandm.h     Sat Jan 12 18:58:10 2019 +0000
+++ b/lib/libwrap/expandm.h     Sat Jan 12 19:08:24 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: expandm.h,v 1.1 2019/01/11 20:37:30 christos Exp $     */
+/*     $NetBSD: expandm.h,v 1.2 2019/01/12 19:08:24 christos Exp $     */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -31,5 +31,6 @@
 #include <sys/cdefs.h>
 
 __BEGIN_DECLS
-char * __attribute__((__format_arg__(1))) expandm(const char *, const char *);
+char * __attribute__((__format_arg__(1))) expandm(const char *, const char *,
+    char **);
 __END_DECLS



Home | Main Index | Thread Index | Old Index