From: Alejandro Colomar <alx.manpages@gmail.com>
To: Siddhesh Poyarekar <siddhesh@gotplt.org>,
Florian Weimer <fweimer@redhat.com>,
libc-alpha@sourceware.org
Subject: Re: [PATCH 1/2] Implement strlcpy and strlcat [BZ #178]
Date: Thu, 6 Apr 2023 23:29:47 +0200 [thread overview]
Message-ID: <354b6c68-c692-25f0-089d-b7d7aad19b63@gmail.com> (raw)
In-Reply-To: <c94c260d-5ac5-04f4-20b8-8af31cd0e5e7@gotplt.org>
Hi Siddhesh,
On 4/6/23 16:22, Siddhesh Poyarekar wrote:
[...]
>> +size_t
>> +__strlcpy (char *__restrict dest, const char *__restrict src, size_t size)
>> +{
>> + size_t src_length = strlen (src);
>> +
>> + if (__glibc_unlikely (src_length >= size))
>> + {
>> + if (size > 0)
>> + {
>> + /* Copy the leading portion of the string. The last
>> + character is subsequently overwritten with the NUL
>> + terminator, but the destination size is usually a
>> + multiple of a small power of two, so writing it twice
>> + should be more efficient than copying an odd number of
>> + bytes. */
>> + memcpy (dest, src, size);
>> + dest[size - 1] = '\0';
>> + }
>> + }
>> + else
>> + /* Copy the string and its terminating NUL character. */
>> + memcpy (dest, src, src_length + 1);
>
> size == 0 is undefined anyway; we return without touching the dest
> because that's convenient for us. OK.
Is it really convenient? What real code benefits of that behavior?
If we remove the conditional it's one less op.
Cheers,
Alex
>
>> + return src_length;
>> +}
next prev parent reply other threads:[~2023-04-06 21:29 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-05 11:20 [PATCH 0/2] strlcpy/strlcat/wcslcpy/wcscat implementation Florian Weimer
2023-04-05 11:20 ` [PATCH 1/2] Implement strlcpy and strlcat [BZ #178] Florian Weimer
2023-04-05 13:18 ` Adhemerval Zanella Netto
2023-04-06 9:18 ` Florian Weimer
2023-04-06 14:22 ` Siddhesh Poyarekar
2023-04-06 15:09 ` Florian Weimer
2023-04-06 21:29 ` Alejandro Colomar [this message]
2023-04-11 14:28 ` Siddhesh Poyarekar
2023-04-20 10:55 ` Florian Weimer
2023-04-20 11:45 ` Siddhesh Poyarekar
2023-04-21 17:45 ` Florian Weimer
2023-04-06 21:21 ` Alejandro Colomar
2023-04-06 21:35 ` Florian Weimer
2023-04-06 22:15 ` Alejandro Colomar
2023-04-06 22:19 ` Alejandro Colomar
2023-04-06 22:34 ` Alejandro Colomar
2023-04-08 22:08 ` Paul Eggert
2023-04-09 15:29 ` Paul Eggert
2023-04-13 11:37 ` Florian Weimer
2023-04-13 14:39 ` Paul Eggert
2023-04-13 17:59 ` Paul Eggert
2023-04-20 8:07 ` Florian Weimer
2023-04-21 19:00 ` Paul Eggert
2023-04-28 8:49 ` Florian Weimer
2023-04-05 11:20 ` [PATCH 2/2] Add the wcslcpy, wcslcat functions Florian Weimer
2023-04-08 22:09 ` Paul Eggert
2023-04-05 12:30 ` [PATCH 0/2] strlcpy/strlcat/wcslcpy/wcscat implementation Alejandro Colomar
2023-04-08 22:05 ` Paul Eggert
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=354b6c68-c692-25f0-089d-b7d7aad19b63@gmail.com \
--to=alx.manpages@gmail.com \
--cc=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=siddhesh@gotplt.org \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).