linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Liu Xiang" <liuxiang_1999@126.com>
To: "Rasmus Villemoes" <linux@rasmusvillemoes.dk>
Cc: linux-kernel@vger.kernel.org
Subject: Re:Re: [PATCH] lib: string: reduce unnecessary loop in strncpy
Date: Thu, 31 Oct 2019 10:29:38 +0800 (CST)	[thread overview]
Message-ID: <fd65c09.2464.16e1fa59f3b.Coremail.liuxiang_1999@126.com> (raw)
In-Reply-To: <c6452618-0161-eefc-0730-b10eac823228@rasmusvillemoes.dk>











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

      reply	other threads:[~2019-10-31  2:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-30 14:14 [PATCH] lib: string: reduce unnecessary loop in strncpy Liu Xiang
2019-10-30 14:59 ` Rasmus Villemoes
2019-10-31  2:29   ` Liu Xiang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fd65c09.2464.16e1fa59f3b.Coremail.liuxiang_1999@126.com \
    --to=liuxiang_1999@126.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).