Source-Changes-HG archive

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

[src/trunk]: src/lib/libwrap Make expandm() return a const char * so we can d...



details:   https://anonhg.NetBSD.org/src/rev/3d016a5d8f4e
branches:  trunk
changeset: 447478:3d016a5d8f4e
user:      kre <kre%NetBSD.org@localhost>
date:      Sat Jan 12 22:14:08 2019 +0000

description:
Make expandm() return a const char * so we can do away with __UNCONST()
and more importantly, so that we don't accidentally return a value
that is a const char * in reality (pointer to read only string) as a
char *.

diffstat:

 lib/libwrap/expandm.c |  14 ++++++--------
 lib/libwrap/expandm.h |   6 +++---
 2 files changed, 9 insertions(+), 11 deletions(-)

diffs (67 lines):

diff -r 58824eefc0fd -r 3d016a5d8f4e lib/libwrap/expandm.c
--- a/lib/libwrap/expandm.c     Sat Jan 12 21:50:29 2019 +0000
+++ b/lib/libwrap/expandm.c     Sat Jan 12 22:14:08 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: expandm.c,v 1.4 2019/01/12 21:50:29 christos Exp $     */
+/*     $NetBSD: expandm.c,v 1.5 2019/01/12 22:14:08 kre 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.4 2019/01/12 21:50:29 christos Exp $");
+__RCSID("$NetBSD: expandm.c,v 1.5 2019/01/12 22:14:08 kre Exp $");
 
 #include <stdio.h>
 #include <string.h>
@@ -38,7 +38,7 @@
 
 #include "expandm.h"
 
-char * __attribute__((__format_arg__(1)))
+const char * __attribute__((__format_arg__(1)))
 expandm(const char *fmt, const char *sf, char **rbuf)
 {
        const char *e = strerror(errno);
@@ -69,7 +69,7 @@
        free(buf);
        if (rbuf)
                *rbuf = NULL;
-       return __UNCONST(fmt);
+       return fmt;
 }
 
 #ifdef TEST
@@ -77,10 +77,8 @@
 main(int argc, char *argv[])
 {
        errno = ERANGE;
-       printf(argv[1]);
-       printf("\n");
-       printf(expandm(argv[1], "\n", NULL));
-       printf("%s\n", expandm(argv[1], NULL, NULL));
+       printf("%s\n", expandm(argc > 1 ? argv[1] : "Message %%m=%m: %%%m%%",
+           "...", NULL));
        return 0;
 }
 #endif
diff -r 58824eefc0fd -r 3d016a5d8f4e lib/libwrap/expandm.h
--- a/lib/libwrap/expandm.h     Sat Jan 12 21:50:29 2019 +0000
+++ b/lib/libwrap/expandm.h     Sat Jan 12 22:14:08 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: expandm.h,v 1.2 2019/01/12 19:08:24 christos Exp $     */
+/*     $NetBSD: expandm.h,v 1.3 2019/01/12 22:14:08 kre Exp $  */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -31,6 +31,6 @@
 #include <sys/cdefs.h>
 
 __BEGIN_DECLS
-char * __attribute__((__format_arg__(1))) expandm(const char *, const char *,
-    char **);
+const char * __attribute__((__format_arg__(1))) expandm(const char *,
+    const char *, char **);
 __END_DECLS



Home | Main Index | Thread Index | Old Index