From: Ingo Molnar <mingo@kernel.org>
To: Lucy Mielke <lucymielke@icloud.com>
Cc: peterz@infradead.org, mingo@redhat.com, will@kernel.org,
longman@redhat.com, boqun.feng@gmail.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] locking/lockdep: fix format-truncation compiler-warning
Date: Thu, 12 Oct 2023 00:11:13 +0200 [thread overview]
Message-ID: <ZScdgaVra/PHRRc/@gmail.com> (raw)
In-Reply-To: <ZSb0B+9otHhd8jCp@fedora.fritz.box>
* Lucy Mielke <lucymielke@icloud.com> wrote:
> Compiler: gcc x86_64 v13.2.1
> Config: allyesconfig, "treat warnings as errors" unset
>
> This fixes a warning emitted by gcc, stating the output may be
> truncated. The fix included increasing the buffer size to the one
> denoted by gcc.
Mind including the output by GCC in the changelog?
> static void seq_time(struct seq_file *m, s64 time)
> {
> - char num[15];
> + char num[22];
>
> snprint_time(num, sizeof(num), time);
> seq_printf(m, " %14s", num);
Fun.
So this:
static void snprint_time(char *buf, size_t bufsiz, s64 nr)
{
s64 div;
s32 rem;
nr += 5; /* for display rounding */
div = div_s64_rem(nr, 1000, &rem);
snprintf(buf, bufsiz, "%lld.%02d", (long long)div, (int)rem/10);
}
... actually needs 21+1 bytes?
Which I suppose is true - longest s64 is "-9223372036854775808"-ish, which
converted to the fixed-point float format above is "-9223372036854775.80":
21 bytes, plus termination is another byte: 22.
Maybe put this into the changelog too, instead of relying on magic GCC
calculations only. :-)
Thanks,
Ingo
next prev parent reply other threads:[~2023-10-11 22:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-11 19:14 [PATCH] locking/lockdep: fix format-truncation compiler-warning Lucy Mielke
2023-10-11 22:11 ` Ingo Molnar [this message]
2023-10-12 10:16 ` Lucy Mielke
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=ZScdgaVra/PHRRc/@gmail.com \
--to=mingo@kernel.org \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=lucymielke@icloud.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will@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