Re: [PATCH v2] writeback: fix -Wstringop-truncation warnings

From: Joe Perches
Date: Thu Jul 25 2019 - 14:08:29 EST


On Thu, 2019-07-25 at 11:50 -0400, Qian Cai wrote:

> > > diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
[]
> > > @@ -66,8 +66,10 @@
> > > ),
> > >
> > > TP_fast_assign(
> > > - strncpy(__entry->name,
> > > - mapping ? dev_name(inode_to_bdi(mapping->host)-
> > > > dev) : "(unknown)", 32);
> > >
> > > + strscpy_pad(__entry->name,
> > > + mapping ?
> > > + dev_name(inode_to_bdi(mapping->host)->dev) :
> > > + "(unknown)", 32);
> >
> > Shouldn't the 32 be 'sizeof (something)' ??
>
> Maybe could do a sizeof(__entry->name) as it is defined as,
>
> TP_STRUCT__entry (
> __array(char, name, 32)
> __field(unsigned long, ino)
> __field(pgoff_t, index)
>
> But, that might be a follow-up patch and does not seem belong here.

stracpy_pad would work one day.