add smb_xvasprintf() panic wrapper around vasprintf
authorAndrew Tridgell <tridge@samba.org>
Sun, 9 Dec 2001 23:56:07 +0000 (23:56 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sun, 9 Dec 2001 23:56:07 +0000 (23:56 +0000)
(This used to be commit fa1e7a62acdbcc550e6b29dc69454dcf7472210d)

source3/lib/util.c

index a8e2bcb7f58efa997e80fd2cf4f5cf529005e2c2..55bb3647fc8227ab238927c4a26e6e1e9dbf81c1 100644 (file)
@@ -1757,7 +1757,6 @@ int smb_mkstemp(char *template)
 /**
  malloc that aborts with smb_panic on fail or zero size.
 **/
-
 void *smb_xmalloc(size_t size)
 {
        void *p;
@@ -1771,7 +1770,6 @@ void *smb_xmalloc(size_t size)
 /**
  Memdup with smb_panic on fail.
 **/
-
 void *smb_xmemdup(const void *p, size_t size)
 {
        void *p2;
@@ -1783,7 +1781,6 @@ void *smb_xmemdup(const void *p, size_t size)
 /**
  strdup that aborts on malloc fail.
 **/
-
 char *smb_xstrdup(const char *s)
 {
        char *s1 = strdup(s);
@@ -1792,6 +1789,19 @@ char *smb_xstrdup(const char *s)
        return s1;
 }
 
+/*
+  vasprintf that aborts on malloc fail
+*/
+int smb_xvasprintf(char **ptr, const char *format, va_list ap)
+{
+       int n;
+       n = vasprintf(ptr, format, ap);
+       if (n == -1 || ! *ptr) {
+               smb_panic("smb_xvasprintf: out of memory");
+       }
+       return n;
+}
+
 /*****************************************************************
 like strdup but for memory
  *****************************************************************/