Re: [PATCH] rcp: Don't call va_start without calling va_end.

Simon Josefsson via Bug reports for the GNU Internet utilities <[email protected]> Mon, 29 Jul 2024 22:46:09 +0200
Newsgroups gmane.comp.gnu.inetutils.bugs
Message-ID <[email protected]>
Collin Funk <[email protected]> writes:

> GCC throws -Wanalyzer-va-list-leak here since the function can return
> before va_end is called. I checked and the NetBSD fixed this along time
> ago. Not sure if it can cause any harm but bad style IMO.

Thanks!  Syncing bugfixes from *BSD is a good idea.

/Simon

> -- 8< --
>
> * src/rcp.c (run_err): Move va_start call after the early return.
> ---
>  src/rcp.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/rcp.c b/src/rcp.c
> index 11b14c44..101f9563 100644
> --- a/src/rcp.c
> +++ b/src/rcp.c
> @@ -1381,11 +1381,12 @@ run_err (const char *fmt, ...)
>    static FILE *fp;
>    va_list ap;
>  
> -  va_start (ap, fmt);
> -
>    ++errs;
>    if (fp == NULL && !(fp = fdopen (rem, "w")))
>      return;
> +
> +  va_start (ap, fmt);
> +
>    fprintf (fp, "%c", 0x01);
>    fprintf (fp, "rcp: ");
>    vfprintf (fp, fmt, ap);
signature.asc (application/pgp-signature, 255 B)
-----BEGIN PGP SIGNATURE-----

iIoEARYIADIWIQSjzJyHC50xCrrUzy9RcisI/kdFogUCZqf/khQcc2ltb25Aam9z
ZWZzc29uLm9yZwAKCRBRcisI/kdFoqTbAQDSQTy+AehPGIpw0sIzWlHNFuT+uKMg
bbMrOtCL+dCiywD/d27a2TG0bsmrbMqKu5TBbkhP8KR0BSYU8J60hTCKoww=
=ZlOA
-----END PGP SIGNATURE-----