blk-throttle: silence truncated string warning
Subsystems (4)
PATCH 1/1 blk-throttle: silence truncated string warning
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.
--- block/blk-throttle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block/blk-throttle.c +2 -2
@@ -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 ;
Signature · 1 line
2.30.2