On 5/30/23 21:35, Bruce Ashfield wrote:
> On Mon, May 29, 2023 at 11:41 PM He Zhe <[email protected]> wrote:
>> Sorry for messy encoding...
>>
>>
>> We met the following warning when build linux-yocto v6.1, introduced by
>> latter diff. It perhaps miscalculates the buf length.
> Are you only seeing it with gcc-13 ?
>
> That fix follows the same pattern as many other parts of the kernel,
> and checking the 6.1 branch, those other subsystems still have similar
> sprintf() changes in place:
>
> i.e.:
>
> switch (cmd) {
> case BLKTRACESETUP:
> snprintf(b, sizeof(b), "%pg", bdev);
The problem is when array is passed as function parameter it'll be treated as a
simple pointer and thus sizeof will return the length of a pointer. This is the
warning is about.
But this doesn't apply to the above case since it passes array directly to
sizeof.
>
> So I don't see a miscalculation of the buffer length in the snippet
> you have below.
>
> The callers of yaffs_devname declare "buf" to be a char array, just as
> the other kernel references I mentioned do. The different being that
> yaffs_devname is an inline function, where the other reference changes
> are not.
>
> What happens if you take the code from the inline function and
> implement it in the calling function, does the warning go away ?
I did a quick test piggybacking print_unknown_bootoptions in init/main.c
static inline char* test_decay(char *buf) {
printk("sizeof(buf) is %lu", sizeof(buf));
snprintf(buf, sizeof(buf), "test_decay");
return buf;
}
static void __init print_unknown_bootoptions(void)
{
char *unknown_options;
char *end;
const char *const *p;
size_t len;
char buf[16];
test_decay(buf);
...
During build we got:
build/tmp-glibc/work-shared/qemux86-64/kernel-source/init/main.c:895:29:
warning: argument to 'sizeof' in 'snprintf' call is the same expression as the
destination; did you mean to provide an explicit length?
[-Wsizeof-pointer-memaccess]
895 | snprintf(buf, sizeof(buf), "test_decay");
|
During boot we got:
...
[ 0.000000] sizeof(buf) is 8
...
I'll send a patch later.
Zhe
>
> Bruce
>
>> fs/yaffs2/yaffs_vfs.c:122:29: warning: argument to 'sizeof' in 'snprintf'
>> call is the same expression as the destination; did you mean to provide an
>> explicit length? [-Wsizeof-pointer-memaccess]
>>
>> --- a/fs/yaffs2/yaffs_vfs.c
>> +++ b/fs/yaffs2/yaffs_vfs.c
>> @@ -117,7 +117,11 @@
>> #define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags)
>>
>> /* FIXME: use sb->s_id instead ? */
>> -#define yaffs_devname(sb, buf) bdevname(sb->s_bdev, buf)
>> +//#define yaffs_devname(sb, buf) bdevname(sb->s_bdev, buf)
>> +static inline char* yaffs_devname(struct super_block *sb, char *buf) {
>> + snprintf(buf, sizeof(buf), "%pg", sb->s_bdev);
>> + return buf;
>> +}
>>
>> #else
>>
>>
>>
>> Thanks,
>> Zhe
>>
>> On 5/30/23 11:34, He Zhe via lists.yoctoproject.org wrote:
>>> |Hi Bruce, We met the following warning when build linux-yocto v6.1,
>>> introduced by latter diff. It perhaps miscalculates the buf length.
>>> fs/yaffs2/yaffs_vfs.c:122:29: warning: argument to 'sizeof' in 'snprintf'
>>> call is the same expression as the destination; did you mean to provide an
>>> explicit length? [-Wsizeof-pointer-memaccess] --- a/fs/yaffs2/yaffs_vfs.c
>>> +++ b/fs/yaffs2/yaffs_vfs.c @@ -117,7 +117,11 @@ #define
>>> Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags) /* FIXME: use
>>> sb->s_id instead ? */ -#define yaffs_devname(sb, buf) bdevname(sb->s_bdev,
>>> buf) +//#define yaffs_devname(sb, buf) bdevname(sb->s_bdev, buf) +static
>>> inline char* yaffs_devname(struct super_block *sb, char *buf) { +
>>> snprintf(buf, sizeof(buf), "%pg", sb->s_bdev); + return buf; +}
>>> #else Thanks, Zhe |
>>>
>>>
>>>
>>>
>
>
>
>
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#12669):
https://lists.yoctoproject.org/g/linux-yocto/message/12669
Mute This Topic: https://lists.yoctoproject.org/mt/99213494/21656
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-