On 12/11/2024 17:42, Song Liu wrote:
On Tue, Nov 12, 2024 at 8:10 AM John Garry<john.g.garry@xxxxxxxxxx> wrote:
For compiling with W=1, the following warning can be seen:
drivers/md/raid5.c: In function ‘setup_conf’:
drivers/md/raid5.c:2423:12: error: ‘%s’ directive output may be truncated writing up to 31 bytes into a region of size between 16 and 26 [-Werror=format-truncation=]
"raid%d-%s", conf->level, mdname(conf->mddev));
^~
drivers/md/raid5.c:2422:3: note: ‘snprintf’ output between 7 and 48 bytes into a destination of size 32
This is a bit confusing. Does this mean we actually need 48 bytes?
I played with it myself, and 38 bytes is indeed enough to silent the
warning. With 38 bytes, we have 4 bytes hole right behind
cache_name, so I am thinking we should just use 40.
WDYT?
Indeed it is confusing...
So the string is "raid%d-%s", which is
4B for "raid"
10B for max int (right?)
1B for '-'
32B for DISK_NAME_LEN
1B for NUL
which totals 48
So I don't know why/how 38 is ok. Maybe there is some auto-padding going
on, like you hint at.
Maybe just using 48 is better.
Thanks,
John