]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdadm.h
Fail overtly when asprintf fails to allocate memory
[thirdparty/mdadm.git] / mdadm.h
diff --git a/mdadm.h b/mdadm.h
index bc4b38e7a5150305a1fc75086a4178f83cb60554..b0a8c5e776b5c4a920461b38195c3b474f24008d 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -528,6 +528,17 @@ extern int open_mddev(char *dev, int autof);
 extern int open_mddev_devnum(char *devname, int devnum, char *name,
                             char *chosen_name, int parts);
 
+#include <assert.h>
+#include <stdarg.h>
+static inline int xasprintf(char **strp, const char *fmt, ...) {
+       va_list ap;
+       int ret;
+       va_start(ap, fmt);
+       ret = asprintf(strp, fmt, ap);
+       va_end(ap);
+       assert(ret >= 0);
+       return ret;
+}
 
 #define        LEVEL_MULTIPATH         (-4)
 #define        LEVEL_LINEAR            (-1)