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

From: Rafael J. Wysocki
Date: Tue Jul 25 2023 - 04:54:20 EST


On Tue, Jul 25, 2023 at 7:08 AM Sunil V L <sunilvl@xxxxxxxxxxxxxxxx> wrote:
>
> On Mon, Jul 24, 2023 at 07:15:22PM +0200, Rafael J. Wysocki wrote:
> > 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
> >
> Thank you very much! Rafael. Let me send a patch to append a NUL
> explicitly to fix this issue. However, I still wonder why this code
> added in 2005 getting this warning only now. Why is this not being seen
> with other architecture builds?

I don't know.