On Fri, Dec 9, 2022 at 9:45 AM <yang.yang29@xxxxxxxxxx> wrote: > > From: Xu Panda <xu.panda@xxxxxxxxxx> > > The implementation of strscpy() is more robust and safer. > That's now the recommended way to copy NUL terminated strings. ... > + strscpy(arg, val, strnchrnul(val, ACTION_LEN - 1, '\n') - val + 1); Instead of -1 +1 you should simply use the sizeof(arg) as I mentioned. strscpy(arg, val, strnchrnul(val, sizeof(arg), '\n') - val); The returned pointer by strnchrnul() either points to the '\n' or to '\0' and when we subtract pointer to the start we will get the exact length of the string. In case it equals ACTION_LEN the last character will be replaced by '\0'. Where am I mistaken? -- With Best Regards, Andy Shevchenko