coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: crusade against strncpy/strcpy ;-)


From: Jim Meyering
Subject: Re: crusade against strncpy/strcpy ;-)
Date: Thu, 19 Apr 2012 14:26:52 +0200

Pádraig Brady wrote:
> On 04/19/2012 12:15 PM, Jim Meyering wrote:
>> strncpy is particularly bad, but even strcpy is best avoided.
>
> Yep, strncpy may not NUL terminate,
> so using it is awkward as detailed here:
> http://www.pixelbeat.org/programming/gcc/string_buffers.html
>
> stpcpy/stpncpy are appropriate here as the buffer is just
> the right size, so you don't waste cycles filling with NULs etc.
>
> Often it's simpler/faster to fall back to memcpy for C string buffers
> as I did in buffer_or_output() here:
> http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=b1428e31
>
> patch looks good.

Pushed.
Thanks for the review.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]