Module Name:    src
Committed By:   kre
Date:           Sat Jan 12 22:14:08 UTC 2019

Modified Files:
        src/lib/libwrap: expandm.c expandm.h

Log Message:
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 *.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libwrap/expandm.c
cvs rdiff -u -r1.2 -r1.3 src/lib/libwrap/expandm.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libwrap/expandm.c
diff -u src/lib/libwrap/expandm.c:1.4 src/lib/libwrap/expandm.c:1.5
--- src/lib/libwrap/expandm.c:1.4	Sat Jan 12 21:50:29 2019
+++ src/lib/libwrap/expandm.c	Sat Jan 12 22:14:08 2019
@@ -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 @@ __RCSID("$NetBSD: expandm.c,v 1.4 2019/0
 
 #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 @@ out:
 	free(buf);
 	if (rbuf)
 		*rbuf = NULL;
-	return __UNCONST(fmt);
+	return fmt;
 }
 
 #ifdef TEST
@@ -77,10 +77,8 @@ int
 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

Index: src/lib/libwrap/expandm.h
diff -u src/lib/libwrap/expandm.h:1.2 src/lib/libwrap/expandm.h:1.3
--- src/lib/libwrap/expandm.h:1.2	Sat Jan 12 19:08:24 2019
+++ src/lib/libwrap/expandm.h	Sat Jan 12 22:14:08 2019
@@ -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

Reply via email to