lkml.org 
[lkml]   [2019]   [Oct]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe:Re: [PATCH] lib: string: reduce unnecessary loop in strncpy










At 2019-10-30 22:59:58, "Rasmus Villemoes" <linux@rasmusvillemoes.dk> wrote:
>On 30/10/2019 15.14, Liu Xiang wrote:
>> Now in strncpy, even src[0] is 0, loop will execute count times until
>> count is 0. It is better to exit the loop immediately when *src is 0.
>
>Please read "man strncpy".
>
>There's a reason the loop is written in that somewhat convoluted way:
>The behavior of strncpy is mandated by the C standard, and if the src
>string is shorter than the destination buffer, the rest must be
>0-filled. So if we hit a nul byte before running out of count, we keep
>copying that nul byte to the rest of the destination.
>
>Rasmus

Hi Rasmus,

Thanks for your explanation. I ignored the C library standard.

Regards

Liu Xiang
\
 
 \ /
  Last update: 2019-10-31 03:30    [W:0.046 / U:1.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site