From: Su Hui <suhui@nfschina.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Su Hui <suhui@nfschina.com>,
tj@kernel.org, josef@toxicpanda.com, axboe@kernel.dk,
cgroups@vger.kernel.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH] blk-throttle: silence truncated string warning
Date: Sun, 8 Oct 2023 09:47:52 +0800 [thread overview]
Message-ID: <20231008014751.423133-1-suhui@nfschina.com> (raw)
using gcc and w=1, there are some warnings like these:
block/blk-throttle.c:1531:53: error:
‘snprintf’ output may be truncated before the last format character
[-Werror=format-truncation=]
1531 | snprintf(idle_time, sizeof(idle_time), " idle=%lu",
| ^
block/blk-throttle.c:1531:4: note: ‘snprintf’ output between 8 and 27 bytes
into a destination of size 26
1531 | snprintf(idle_time, sizeof(idle_time), " idle=%lu",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1532 | tg->idletime_threshold_conf);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
block/blk-throttle.c:1538:15: error:
‘%lu’ directive output may be truncated writing between 1 and 20 bytes
into a region of size 17 [-Werror=format-truncation=]
1538 | " latency=%lu", tg->latency_target_conf);
| ^~~
"%lu" can up to 21, so string " idle=%lu" can up to 27. But 'idle_time'
only has 26 Bytes. It's same for 'latency_time' whose size should be 30
rather than 26 because string " latency=%lu" can up to 30.
Signed-off-by: Su Hui <suhui@nfschina.com>
---
block/blk-throttle.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 38a881cf97d0..dfc5c0d3d9c1 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -1489,8 +1489,8 @@ static u64 tg_prfill_limit(struct seq_file *sf, struct blkg_policy_data *pd,
char bufs[4][21] = { "max", "max", "max", "max" };
u64 bps_dft;
unsigned int iops_dft;
- char idle_time[26] = "";
- char latency_time[26] = "";
+ char idle_time[27] = "";
+ char latency_time[30] = "";
if (!dname)
return 0;
--
2.30.2
reply other threads:[~2023-10-08 1:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20231008014751.423133-1-suhui@nfschina.com \
--to=suhui@nfschina.com \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=josef@toxicpanda.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@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
all inboxes | Powered by JetHome®