Re: [PATCH] error.c: fix gcc warning (vasprintf)

Kalle Olavi Niemitalo <[email protected]>
Newsgroups gmane.comp.web.links
Message-ID <[email protected]>
Alexey Tourbin <[email protected]> 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)

_______________________________________________
elinks-dev mailing list
[email protected]
http://linuxfromscratch.org/mailman/listinfo/elinks-dev
signature.asc (application/pgp-signature, 188 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGKGgZHm9IGt60eMgRAvqWAJ9EHWZ8Ib9wScZAwwiUj9ZyS2I0QQCgzk6w
50CQwrkmEakqqVK8nJ45KzI=
=xxGl
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.