summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmalloc.c21
-rw-r--r--xmalloc.h4
2 files changed, 17 insertions, 8 deletions
diff --git a/xmalloc.c b/xmalloc.c
index 9cd0127dd..b48d33bbf 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: xmalloc.c,v 1.35 2019/06/06 05:13:13 otto Exp $ */ 1/* $OpenBSD: xmalloc.c,v 1.36 2019/11/12 22:32:48 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -96,17 +96,24 @@ xstrdup(const char *str)
96} 96}
97 97
98int 98int
99xvasprintf(char **ret, const char *fmt, va_list ap)
100{
101 int i;
102
103 i = vasprintf(ret, fmt, ap);
104 if (i < 0 || *ret == NULL)
105 fatal("xvasprintf: could not allocate memory");
106 return i;
107}
108
109int
99xasprintf(char **ret, const char *fmt, ...) 110xasprintf(char **ret, const char *fmt, ...)
100{ 111{
101 va_list ap; 112 va_list ap;
102 int i; 113 int i;
103 114
104 va_start(ap, fmt); 115 va_start(ap, fmt);
105 i = vasprintf(ret, fmt, ap); 116 i = xvasprintf(ret, fmt, ap);
106 va_end(ap); 117 va_end(ap);
107 118 return i;
108 if (i < 0 || *ret == NULL)
109 fatal("xasprintf: could not allocate memory");
110
111 return (i);
112} 119}
diff --git a/xmalloc.h b/xmalloc.h
index 1d5f62df7..abaf7ada2 100644
--- a/xmalloc.h
+++ b/xmalloc.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: xmalloc.h,v 1.18 2019/06/06 05:13:13 otto Exp $ */ 1/* $OpenBSD: xmalloc.h,v 1.19 2019/11/12 22:32:48 djm Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -24,3 +24,5 @@ char *xstrdup(const char *);
24int xasprintf(char **, const char *, ...) 24int xasprintf(char **, const char *, ...)
25 __attribute__((__format__ (printf, 2, 3))) 25 __attribute__((__format__ (printf, 2, 3)))
26 __attribute__((__nonnull__ (2))); 26 __attribute__((__nonnull__ (2)));
27int xvasprintf(char **, const char *, va_list)
28 __attribute__((__nonnull__ (2)));