Re: drivers/pnp/pnpacpi/core.c:253:17: warning: 'strncpy' specified bound 50 equals destination size

From: Rafael J. Wysocki
Date: Mon Jul 24 2023 - 13:15:46 EST


On Mon, Jul 24, 2023 at 4:20 PM Sunil V L <sunilvl@xxxxxxxxxxxxxxxx> wrote:
>
> +Rafael.
>
> On Mon, Jul 24, 2023 at 07:32:36PM +0800, kernel test robot wrote:
> > tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> > head: 6eaae198076080886b9e7d57f4ae06fa782f90ef
> > commit: a91a9ffbd3a55a0ae1bb75e2b6e85b2a03f64e8f RISC-V: Add support to build the ACPI core
> > date: 8 weeks ago
> > config: riscv-randconfig-r032-20230724 (https://download.01.org/0day-ci/archive/20230724/202307241942.Rff2Nri5-lkp@xxxxxxxxx/config)
> > compiler: riscv64-linux-gcc (GCC) 12.3.0
> > reproduce: (https://download.01.org/0day-ci/archive/20230724/202307241942.Rff2Nri5-lkp@xxxxxxxxx/reproduce)
> >
> > If you fix the issue in a separate patch/commit (i.e. not just a new version of
> > the same patch/commit), kindly add following tags
> > | Reported-by: kernel test robot <lkp@xxxxxxxxx>
> > | Closes: https://lore.kernel.org/oe-kbuild-all/202307241942.Rff2Nri5-lkp@xxxxxxxxx/
> >
> > All warnings (new ones prefixed by >>):
> >
> > drivers/pnp/pnpacpi/core.c: In function 'pnpacpi_add_device.isra':
> > >> drivers/pnp/pnpacpi/core.c:253:17: warning: 'strncpy' specified bound 50 equals destination size [-Wstringop-truncation]
> > 253 | strncpy(dev->name, acpi_device_name(device), sizeof(dev->name));
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> I need some help here to understand what needs to be done. This is a
> common code across architectures. Apart from the fact that ACPI is
> enabled for the first time for RISC-V, I am unable to understand why
> this warning is seen now. Is this because only RISC-V gcc enables this
> warning by default? I don't see this with clang tool chain. If this is
> expected warning, is there a way to suppress?

I think that this is relevant information:

https://stackoverflow.com/questions/50198319/gcc-8-wstringop-truncation-what-is-the-good-practice

Thanks!