[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VckYszyD6eU8n4W75pGWrnWzo3GZ4rVg+8iwEs_4xJErA@mail.gmail.com>
Date: Thu, 5 Dec 2019 18:47:50 +0200
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Bartosz Golaszewski <brgl@...ev.pl>
Cc: Bartosz Golaszewski <bgolaszewski@...libre.com>,
Kent Gibson <warthog618@...il.com>,
Linus Walleij <linus.walleij@...aro.org>,
"open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 09/11] gpiolib: provide a dedicated function for
setting lineinfo
On Thu, Dec 5, 2019 at 3:45 PM Bartosz Golaszewski <brgl@...ev.pl> wrote:
> czw., 5 gru 2019 o 11:21 Andy Shevchenko <andy.shevchenko@...il.com> napisał(a):
> > On Thu, Dec 5, 2019 at 11:28 AM Bartosz Golaszewski
> > <bgolaszewski@...libre.com> wrote:
> > > śr., 4 gru 2019 o 23:30 Andy Shevchenko <andy.shevchenko@...il.com> napisał(a):
> > > > On Wed, Dec 4, 2019 at 6:02 PM Bartosz Golaszewski <brgl@...ev.pl> wrote:
> > > > > + if (desc->name) {
> > > > > + strncpy(info->name, desc->name, sizeof(info->name));
> > > > > + info->name[sizeof(info->name) - 1] = '\0';
> > > > > + } else {
> > > > > + info->name[0] = '\0';
> > > > > + }
> > > > > +
> > > > > + if (desc->label) {
> > > > > + strncpy(info->consumer, desc->label, sizeof(info->consumer));
> > > > > + info->consumer[sizeof(info->consumer) - 1] = '\0';
> > > > > + } else {
> > > > > + info->consumer[0] = '\0';
> > > > > + }
> > > >
> > > > I think we have to fix GCC warnings first and then do whatever this patch does.
> > > >
> > >
> > > What GCC warnings are you referring to exactly?
> >
> > stncpy() against partial string without NUL-terminator.
> >
> > So, if desc->label is longer than info->consumer, it will be copied
> > partially. I don't check if the modern GCC clever enough to see the
> > next operation which does the termination.
> >
>
> I'm not sure I get it. What warnings does it produce and in what
> environment?
Some kind of
warning: ‘strncpy’ specified bound 16 equals destination size
[-Wstringop-truncation]
> I don't see any.
Good, I just checked and see none as well. It means GCC understands
that strncpy() is followed by guaranteed NUL-termination.
> If you want it simpler - we can do `snprintf(info->consumer,
> sizeof(info->consumer), desc->label ?: "")`.
It makes sense only in above context.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists