direct-io.hg

changeset 15249:93f77a5a8437

tools: Fix xenstored build error by checking vasprintf() return code.
Signed-off-by: Charles Coffing <ccoffing@novell.com>
author Keir Fraser <keir@xensource.com>
date Sun Jun 10 19:58:22 2007 +0100 (2007-06-10)
parents 7eeddd787d2f
children a43a03d53781
files tools/xenstore/utils.c
line diff
     1.1 --- a/tools/xenstore/utils.c	Sun Jun 10 19:49:44 2007 +0100
     1.2 +++ b/tools/xenstore/utils.c	Sun Jun 10 19:58:22 2007 +0100
     1.3 @@ -27,33 +27,38 @@ void xprintf(const char *fmt, ...)
     1.4  void barf(const char *fmt, ...)
     1.5  {
     1.6  	char *str;
     1.7 +	int bytes;
     1.8  	va_list arglist;
     1.9  
    1.10  	xprintf("FATAL: ");
    1.11  
    1.12  	va_start(arglist, fmt);
    1.13 -	vasprintf(&str, fmt, arglist);
    1.14 +	bytes = vasprintf(&str, fmt, arglist);
    1.15  	va_end(arglist);
    1.16  
    1.17 -	xprintf("%s\n", str);
    1.18 -	free(str);
    1.19 + 	if (bytes >= 0) {
    1.20 +		xprintf("%s\n", str);
    1.21 +		free(str);
    1.22 +	}
    1.23  	exit(1);
    1.24  }
    1.25  
    1.26  void barf_perror(const char *fmt, ...)
    1.27  {
    1.28  	char *str;
    1.29 -	int err = errno;
    1.30 +	int bytes, err = errno;
    1.31  	va_list arglist;
    1.32  
    1.33  	xprintf("FATAL: ");
    1.34  
    1.35  	va_start(arglist, fmt);
    1.36 -	vasprintf(&str, fmt, arglist);
    1.37 +	bytes = vasprintf(&str, fmt, arglist);
    1.38  	va_end(arglist);
    1.39  
    1.40 -	xprintf("%s: %s\n", str, strerror(err));
    1.41 -	free(str);
    1.42 + 	if (bytes >= 0) {
    1.43 +		xprintf("%s: %s\n", str, strerror(err));
    1.44 +		free(str);
    1.45 +	}
    1.46  	exit(1);
    1.47  }
    1.48