Skip to contentSkip to conversation

fix xenstored build error

PATCH New Charles Coffing 1 participant 1 message Jun 8, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix xenstored build error

tools/xenstore/Makefile includes -Werror, so warnings are fatal. I just hit this:

gcc -O2 -march=i586 -mtune=i686 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -m32 -march=i686 -DNDEBUG -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -m32 -march=i686 -DNDEBUG -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -m32 -march=i686 -DNDEBUG -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -D__XEN_TOOLS__ -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -mno-tls-direct-seg-refs -m32 -march=i686 -DNDEBUG -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -D__XEN_TOOLS__ -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -mno-tls-direct-seg-refs -Werror -Wp,-MD,.utils.o.d -I../../tools/libxc -I. -c -o utils.o utils.c
cc1: warnings being treated as errors
utils.c: In function 'barf':
utils.c:35: warning: ignoring return value of 'vasprintf', declared with attribute warn_unused_result
utils.c: In function 'barf_perror':
utils.c:52: warning: ignoring return value of 'vasprintf', declared with attribute warn_unused_result

Indeed, if vasprintf fails to allocate memory, then the process could crash. (True, this is on an exit path anyway, but crashing is nevertheless poor manners...) The attached patch handles failed allocations more gracefully, which in turn allows my builds to complete.

Please apply to xen-unstable.

tools/xenstore/utils.c +12 -7
@@ -27,33 +27,38 @@ void xprintf(const char *fmt, ...)
 void barf(const char *fmt, ...)
 {
 	char *str;
+	int bytes;
 	va_list arglist;
 
 	xprintf("FATAL: ");
 
 	va_start(arglist, fmt);
-	vasprintf(&str, fmt, arglist);
+	bytes = vasprintf(&str, fmt, arglist);
 	va_end(arglist);
 
-	xprintf("%s\n", str);
-	free(str);
+ 	if (bytes >= 0) {
+		xprintf("%s\n", str);
+		free(str);
+	}
 	exit(1);
 }
 
 void barf_perror(const char *fmt, ...)
 {
 	char *str;
-	int err = errno;
+	int bytes, err = errno;
 	va_list arglist;
 
 	xprintf("FATAL: ");
 
 	va_start(arglist, fmt);
-	vasprintf(&str, fmt, arglist);
+	bytes = vasprintf(&str, fmt, arglist);
 	va_end(arglist);
 
-	xprintf("%s: %s\n", str, strerror(err));
-	free(str);
+ 	if (bytes >= 0) {
+		xprintf("%s: %s\n", str, strerror(err));
+		free(str);
+	}
 	exit(1);
 }
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel