Re: [PATCH linux-next v2] x86/platform/uv: use strscpy to instead of strncpy()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Dec 5, 2022 at 3:13 PM Andy Shevchenko
<andy.shevchenko@xxxxxxxxx> wrote:
> On Mon, Dec 5, 2022 at 1:42 PM <yang.yang29@xxxxxxxxxx> wrote:

...

> >         char arg[ACTION_LEN], *p;
> >
> >         /* (remove possible '\n') */
> > -       strncpy(arg, val, ACTION_LEN - 1);
> > -       arg[ACTION_LEN - 1] = '\0';
> > -       p = strchr(arg, '\n');
> > -       if (p)
> > -               *p = '\0';
> > +       strscpy(arg, val, strnchrnul(val, ACTION_LEN, '\n') - val);
>
> And even better is to replace ACTION_LEN by sizeof(arg).

Btw, have you compiled this with `make W=1 ...`? I believe you will
get a new warning after your change.

-- 
With Best Regards,
Andy Shevchenko



[Index of Archives]     [Linux Kernel Development]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux