public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] replace sprintf with strcpy to avoid GCC warning [BZ#28439]
@ 2021-10-09 19:27 Martin Sebor
  2021-10-09 20:16 ` Florian Weimer
  0 siblings, 1 reply; 11+ messages in thread
From: Martin Sebor @ 2021-10-09 19:27 UTC (permalink / raw)
  To: GNU C Library

The patch below replaces a call to sprintf with an equivalent
pair of strcpy calls to avoid a GCC false positive due to
a recent optimizer improvement (still under review).

I considered using #pragma GCC diagnostic but using strcpy
here seems to me preferable than sprintf: thanks to
the precondition check it's equally as safe but lighter-weight
and no less readable.

Tested on x86_64-linux running Fedora 29.

Martin

index 75b0e5f2f7..31ab1db60b 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);
+               strcpy (nbuf, name);
+               nbuf[n] = '.';
+               strcpy (nbuf + n + 1, domain);
         }
         return __res_context_query (ctx, longname, class, type, answer,
                                     anslen, answerp, answerp2, nanswerp2,

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-10-11 15:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-09 19:27 [PATCH] replace sprintf with strcpy to avoid GCC warning [BZ#28439] Martin Sebor
2021-10-09 20:16 ` Florian Weimer
2021-10-09 20:56   ` [PATCH v2] " Martin Sebor
2021-10-09 21:15     ` Florian Weimer
2021-10-09 21:20       ` Martin Sebor
2021-10-10  8:28         ` Florian Weimer
2021-10-11 15:42           ` Martin Sebor
2021-10-09 21:57     ` Paul Eggert
2021-10-09 23:43       ` [PATCH v3] replace sprintf with stpcpy " Martin Sebor
2021-10-10 13:53         ` Florian Weimer
2021-10-11 15:43           ` Martin Sebor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).