[PATCH v3] replace sprintf with stpcpy to avoid GCC warning [BZ#28439]

Florian Weimer fw@deneb.enyo.de
Sun Oct 10 13:53:37 GMT 2021


* Martin Sebor:

> diff --git a/resolv/res_query.c b/resolv/res_query.c
> index 75b0e5f2f7..5d0a68dc81 100644
> --- a/resolv/res_query.c
> +++ b/resolv/res_query.c
> @@ -610,7 +610,9 @@ __res_context_querydomain (struct resolv_context *ctx,
>  			RES_SET_H_ERRNO(statp, NO_RECOVERY);
>  			return (-1);
>  		}
> -		sprintf(nbuf, "%s.%s", name, domain);
> +		char *p = __stpcpy (nbuf, name);
> +		*p++ = '.';
> +		strcpy (p, domain);
>  	}
>  	return __res_context_query (ctx, longname, class, type, answer,
>  				    anslen, answerp, answerp2, nanswerp2,

I don't see any problems with this patch, although I dislike the use
of stpcpy in general (mempcpy and stpcopy are both closely associated
with buggy code).


More information about the Libc-alpha mailing list