Re: include/linux/string.h:246:9: warning: '__builtin_strncpy' output truncated before terminating nul copying 4 bytes from a string of the same length
From: Andy Shevchenko
Date: Tue Jun 05 2018 - 11:31:47 EST
On Tue, Jun 5, 2018 at 6:30 PM, Josh Poimboeuf <jpoimboe@xxxxxxxxxx> wrote:
> On Tue, Jun 05, 2018 at 06:19:07PM +0300, Andy Shevchenko wrote:
>> On Tue, May 29, 2018 at 4:35 AM, kbuild test robot <lkp@xxxxxxxxx> wrote:
>> > tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
>> > head: 786b71f5b754273ccef6d9462e52062b3e1f9877
>> > commit: 854e55ad289ef8888e7991f0ada85d5846f5afb9 objtool, perf: Fix GCC 8 -Wrestrict error
>> > date: 2 months ago
>> > config: x86_64-randconfig-s4-05290856 (attached as .config)
>> > compiler: gcc-8 (Debian 8.1.0-3) 8.1.0
>> > reproduce:
>> > git checkout 854e55ad289ef8888e7991f0ada85d5846f5afb9
>> > # save the attached .config to linux build tree
>> > make ARCH=x86_64
>> >
>>
>> I guess it's easy to fix by
>>
>> --- a/drivers/video/fbdev/uvesafb.c
>> +++ b/drivers/video/fbdev/uvesafb.c
>> @@ -422,7 +422,7 @@ static int uvesafb_vbe_getinfo(struct uvesafb_ktask *task,
>> task->t.flags = TF_VBEIB;
>> task->t.buf_len = sizeof(struct vbe_ib);
>> task->buf = &par->vbe_ib;
>> - strncpy(par->vbe_ib.vbe_signature, "VBE2", 4);
>> + snprintf(par->vbe_ib.vbe_signature,
>> sizeof(par->vbe_ib.vbe_signature), "VBE2");
>>
>> The question is do we want this to just shut up a compiler? It's
>> obviously false positive.
>
> What about just changing it to a memcpy? Seems like that would be
> cleaner anyway, since the whole point of strncpy is to add the
> terminating NULL, which isn't need here.
Agree.
Btw, Bartlomiej, it seems driver maintainer's address is bouncing.
--
With Best Regards,
Andy Shevchenko