This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Implement C11 annex K?
- From: Rich Felker <dalias at libc dot org>
- To: Russ Allbery <eagle at eyrie dot org>
- Cc: libc-alpha at sourceware dot org
- Date: Thu, 14 Aug 2014 01:46:10 -0400
- Subject: Re: Implement C11 annex K?
- Authentication-results: sourceware.org; auth=none
- References: <E1XHe8v-0004Ur-Hp at rmm6prod02 dot runbox dot com> <Pine dot LNX dot 4 dot 64 dot 1408132054090 dot 16622 at digraph dot polyomino dot org dot uk> <53EBD7D9 dot 1040008 at cs dot ucla dot edu> <20140813213520 dot GQ12888 at brightrain dot aerifal dot cx> <53EBEACD dot 3070000 at googlemail dot com> <87k36cc559 dot fsf at windlord dot stanford dot edu> <20140814022501 dot GT12888 at brightrain dot aerifal dot cx> <87r40jbq2p dot fsf at windlord dot stanford dot edu>
On Wed, Aug 13, 2014 at 10:25:18PM -0700, Russ Allbery wrote:
> Rich Felker <dalias@libc.org> writes:
> > On Wed, Aug 13, 2014 at 04:59:46PM -0700, Russ Allbery wrote:
>
> >> If the answer is "use strcpy and strcat because this code is provably
> >> correct with them," I guess I understand your position, but if I
> >> somehow
>
> > The answer is "use memcpy".
>
> memcpy would make that code harder to read and understand, or at least it
> did when I tried to write it that way. Instead of:
Indeed, I misread. Since you're already computing the lengths to
allocate the right storage, but don't have storage to keep the
computed lengths, it's inefficient and ugly to compute them again.
This is one case where GNY stpcpy, or using snprintf as a substitute
for it, is probably the right solution.
Certainly strlcpy/strlcat are not needed here since the length is
known to be correct.
Rich