summaryrefslogtreecommitdiff
path: root/lib/libwrap
diff options
context:
space:
mode:
authorkre <kre@NetBSD.org>2019-01-12 22:14:08 +0000
committerkre <kre@NetBSD.org>2019-01-12 22:14:08 +0000
commit0f2ce139f285641cc1b57167b743cf5c9f2b1d8c (patch)
tree90aac1ab9d6d299053da44b32c54230e62ede062 /lib/libwrap
parentd501129c7a4435adc635db31e81fdddd18b1d452 (diff)
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 (limited to 'lib/libwrap')
-rw-r--r--lib/libwrap/expandm.c14
-rw-r--r--lib/libwrap/expandm.h6
2 files changed, 9 insertions, 11 deletions
diff --git a/lib/libwrap/expandm.c b/lib/libwrap/expandm.c
index 5a3adc905c2..a2a23dc7458 100644
--- a/lib/libwrap/expandm.c
+++ b/lib/libwrap/expandm.c
@@ -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/01/12 21:50:29 christos Exp $");
#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
diff --git a/lib/libwrap/expandm.h b/lib/libwrap/expandm.h
index 16c38257c2c..1e3c1b746ee 100644
--- a/lib/libwrap/expandm.h
+++ b/lib/libwrap/expandm.h
@@ -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