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:

>  	va_start(params, fmt);
> -	vasprintf((char **) &buf, fmt, params);
> +	rv = vasprintf((char **) &buf, fmt, params);
> +	if (rv < 0) {
> +		perror("vasprintf");
> +		return;
> +	}
>  	va_end(params);
>  	elinks_internal("assertion failed: %s", buf);

This is wrong.  va_end and elinks_internal must be called even if
vasprintf fails.

Possibilities to be handled:
(a) vasprintf returns an error and doesn't alter buf.  Because
    buf is initialized as NULL, this is the same as (b).
(b) vasprintf returns an error and sets buf = NULL.  This NULL
    should not be passed to elinks_internal because it will go
    to snprintf from there and perhaps cause a crash.  The NULL
    could be replaced with an empty string.  Displaying the
    error from vasprintf may be useful but may also distract
    users into reporting that error instead of the file name and
    line number.
(c) vasprintf returns an error but sets buf != NULL.  In this
    case the string probably contains something sensible so it
    should be used.
(d) vasprintf returns success but sets buf = NULL.  That should
    not be possible.
(e) vasprintf returns success and sets buf != NULL.  This is the
    usual case.

_______________________________________________
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)

iD8DBQFF5JfwHm9IGt60eMgRApTzAJ4oTUMlxt1IiEtsaK0he2xxGPHQegCguIXd
s+NBQ8w7/QY1SfSG5YdRpPw=
=6AzN
-----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.