On Fri, 2008-12-19 at 16:02 +1100, Neil Brown wrote:
> I'm not really keen on taking this sort of patch.
> It isn't clear that an abort (caused by the assert) is really much
> better than just segfaulting normally ... though you do get a message
> I guess.
> But it makes the code rather ugly.
> 
> Maybe if you defined a asprintf_nofail (possibly an inline in mdadm.h)
> and called that it would be acceptable.

Hi Neil, et al-

I have an updated patch attached.

I actually called the function xasprintf(), as that seems to be used
elsewhere.

I have verified that this code builds, but I have not functionally
tested it.

Perhaps you're more willing to accept something like this?

-- 
:-Dustin

Dustin Kirkland
Ubuntu Server Developer
Canonical, LTD
kirkl...@canonical.com
GPG: 1024D/83A61194
diff -uprN mdadm-2.6.7.1.orig/Assemble.c mdadm-2.6.7.1/Assemble.c
--- mdadm-2.6.7.1.orig/Assemble.c	2008-10-15 00:29:37.000000000 -0500
+++ mdadm-2.6.7.1/Assemble.c	2009-01-05 18:35:02.021045097 -0600
@@ -386,9 +386,9 @@ int Assemble(struct supertype *st, char 
 		if (c) c++; else c= info.name;
 		if (isdigit(*c) && ((ident->autof & 7)==4 || (ident->autof&7)==6))
 			/* /dev/md/d0 style for partitionable */
-			asprintf(&mddev, "/dev/md/d%s", c);
+			xasprintf(&mddev, "/dev/md/d%s", c);
 		else
-			asprintf(&mddev, "/dev/md/%s", c);
+			xasprintf(&mddev, "/dev/md/%s", c);
 		mdfd = open_mddev(mddev, ident->autof);
 		if (mdfd < 0) {
 			st->ss->free_super(st);
diff -uprN mdadm-2.6.7.1.orig/config.c mdadm-2.6.7.1/config.c
--- mdadm-2.6.7.1.orig/config.c	2008-10-12 21:46:39.000000000 -0500
+++ mdadm-2.6.7.1/config.c	2009-01-05 18:35:17.477104526 -0600
@@ -559,7 +559,7 @@ void mailfromline(char *line)
 			alert_mail_from = strdup(w);
 		else {
 			char *t= NULL;
-			asprintf(&t, "%s %s", alert_mail_from, w);
+			xasprintf(&t, "%s %s", alert_mail_from, w);
 			free(alert_mail_from);
 			alert_mail_from = t;
 		}
diff -uprN mdadm-2.6.7.1.orig/mdadm.h mdadm-2.6.7.1/mdadm.h
--- mdadm-2.6.7.1.orig/mdadm.h	2008-10-15 00:29:37.000000000 -0500
+++ mdadm-2.6.7.1/mdadm.h	2009-01-05 18:49:34.061044664 -0600
@@ -527,6 +527,17 @@ extern int open_mddev(char *dev, int aut
 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)

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to