public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: GNU C Library <libc-alpha@sourceware.org>
Subject: [PATCH] replace sprintf with strcpy to avoid GCC warning [BZ#28439]
Date: Sat, 9 Oct 2021 13:27:23 -0600	[thread overview]
Message-ID: <8bc40ccb-9d82-77c9-1277-cbff062b4ce6@gmail.com> (raw)

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,

             reply	other threads:[~2021-10-09 19:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-09 19:27 Martin Sebor [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8bc40ccb-9d82-77c9-1277-cbff062b4ce6@gmail.com \
    --to=msebor@gmail.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).