[elinks-dev] [PATCH] error.c: fix gcc warning (vasprintf)

Kalle Olavi Niemitalo kon at iki.fi
Fri Apr 20 01:13:22 MDT 2007


Alexey Tourbin <at at altlinux.ru> writes:

> +	rv = vasprintf((char **) &buf, fmt, params);
> +	if (rv < 0)
> +		buf = fmt;
>  	va_end(params);
>  	elinks_internal("assertion failed: %s", buf);
>  	if (buf) free(buf);

It can then call free(fmt) and probably get a SIGSEGV.
Would you be happy with the following?

diff --git a/src/util/error.c b/src/util/error.c
index 34e4c88..4e6afe5 100644
--- a/src/util/error.c
+++ b/src/util/error.c
@@ -147,17 +147,17 @@ elinks_assertm(int x, unsigned char *fmt, ...)
 	unsigned char *buf = NULL;
 	va_list params;
 
 	if (assert_failed) return;
 	if (!(assert_failed = !x)) return;
 
 	va_start(params, fmt);
-	vasprintf((char **) &buf, fmt, params);
+	(void) vasprintf((char **) &buf, fmt, params);
 	va_end(params);
-	elinks_internal("assertion failed: %s", buf);
+	elinks_internal("assertion failed: %s", buf ? buf : fmt);
 	if (buf) free(buf);
 }
 
 
 #ifdef CONFIG_DEBUG
 void
 force_dump(void)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
Url : http://linuxfromscratch.org/pipermail/elinks-dev/attachments/20070420/c9b176c3/attachment.bin 


More information about the elinks-dev mailing list