]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: add xvasprintf()
authordjm@openbsd.org <djm@openbsd.org>
Tue, 12 Nov 2019 22:32:48 +0000 (22:32 +0000)
committerDamien Miller <djm@mindrot.org>
Tue, 12 Nov 2019 23:15:46 +0000 (10:15 +1100)
OpenBSD-Commit-ID: e5e3671c05c121993b034db935bce1a7aa372247

xmalloc.c
xmalloc.h

index 9cd0127dd3c7c90ad73584203dadf0554716627c..b48d33bbf68c4ccff660201913a3bbbab6c30bce 100644 (file)
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xmalloc.c,v 1.35 2019/06/06 05:13:13 otto Exp $ */
+/* $OpenBSD: xmalloc.c,v 1.36 2019/11/12 22:32:48 djm Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -95,6 +95,17 @@ xstrdup(const char *str)
        return cp;
 }
 
+int
+xvasprintf(char **ret, const char *fmt, va_list ap)
+{
+       int i;
+
+       i = vasprintf(ret, fmt, ap);
+       if (i < 0 || *ret == NULL)
+               fatal("xvasprintf: could not allocate memory");
+       return i;
+}
+
 int
 xasprintf(char **ret, const char *fmt, ...)
 {
@@ -102,11 +113,7 @@ xasprintf(char **ret, const char *fmt, ...)
        int i;
 
        va_start(ap, fmt);
-       i = vasprintf(ret, fmt, ap);
+       i = xvasprintf(ret, fmt, ap);
        va_end(ap);
-
-       if (i < 0 || *ret == NULL)
-               fatal("xasprintf: could not allocate memory");
-
-       return (i);
+       return i;
 }
index 1d5f62df77a37898b06a20919b7235587e9d1b80..abaf7ada2c6c508d2c86854fec01c31c90ca30fc 100644 (file)
--- a/xmalloc.h
+++ b/xmalloc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: xmalloc.h,v 1.18 2019/06/06 05:13:13 otto Exp $ */
+/* $OpenBSD: xmalloc.h,v 1.19 2019/11/12 22:32:48 djm Exp $ */
 
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -24,3 +24,5 @@ char  *xstrdup(const char *);
 int     xasprintf(char **, const char *, ...)
                 __attribute__((__format__ (printf, 2, 3)))
                 __attribute__((__nonnull__ (2)));
+int     xvasprintf(char **, const char *, va_list)
+               __attribute__((__nonnull__ (2)));