From: Christoph Hellwig <hch@infradead.org>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: Carlos Maiolino <cmaiolino@redhat.com>, xfs <linux-xfs@vger.kernel.org>
Subject: Re: [PATCH] misc: fix string buffer compile warnings
Date: Tue, 12 Mar 2024 14:20:27 -0700 [thread overview]
Message-ID: <ZfDHG7arXUYlKGcd@infradead.org> (raw)
In-Reply-To: <20240312161242.GA1927156@frogsfrogsfrogs>
Funnily enough I just started looking into xfsdump warnings a few
minutes ago..
> --- a/common/global.c
> +++ b/common/global.c
> @@ -82,7 +82,7 @@ global_hdr_alloc(int argc, char *argv[])
>
> /* fill in the magic number
> */
> - strncpy(ghdrp->gh_magic, GLOBAL_HDR_MAGIC, GLOBAL_HDR_MAGIC_SZ);
> + memcpy(ghdrp->gh_magic, GLOBAL_HDR_MAGIC, GLOBAL_HDR_MAGIC_SZ);
This chunk and all the other ones switching to memcpy where we have
a fixed size look good and impossible to improve on to me.
> - sprintf(question,
> + snprintf(question, sizeof(question),
> "pre-erase (-%c) option specified "
> "and non-blank media encountered:\n"
> "please confirm media erase "
> diff --git a/invutil/fstab.c b/invutil/fstab.c
For this and a few others that just s(n)printf I wonder if just
switching to asprintf and dynamically allocating the buffer is
the right thing to do. That's a GNU/BSD extension, but we probably
don't care about anything else.
> index 88d849e..56132e1 100644
> --- a/invutil/fstab.c
> +++ b/invutil/fstab.c
> @@ -149,7 +149,7 @@ fstab_select(WINDOW *win, node_t *current, node_t *list)
> int
> fstab_highlight(WINDOW *win, node_t *current, node_t *list)
> {
> - static char txt[256];
> + static char txt[512];
And for put_info_line/put_line I suspect just passing a format
string is the best thing to do, as this avoids the extra
snprintf and buffer entirely. That's in fact what I had just started
on.
prev parent reply other threads:[~2024-03-12 21:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-12 16:12 [PATCH] misc: fix string buffer compile warnings Darrick J. Wong
2024-03-12 21:20 ` Christoph Hellwig [this message]
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=ZfDHG7arXUYlKGcd@infradead.org \
--to=hch@infradead.org \
--cc=cmaiolino@redhat.com \
--cc=djwong@kernel.org \
--cc=linux-xfs@vger.kernel.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