This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH][BZ #431] Fix manual of strncat/wcsncat.
- From: "Carlos O'Donell" <carlos at redhat dot com>
- To: OndÅej BÃlka <neleai at seznam dot cz>
- Cc: libc-alpha at sourceware dot org
- Date: Thu, 03 Oct 2013 04:52:33 -0400
- Subject: Re: [PATCH][BZ #431] Fix manual of strncat/wcsncat.
- Authentication-results: sourceware.org; auth=none
- References: <20131003083651 dot GA23447 at domone dot podge>
On 10/03/2013 04:36 AM, OndÅej BÃlka wrote:
> Hi, this is quite old bug that implementation of strncat in manual is
> wrong. This replaces it with correct one
>
> * manual/string.texi: Fix strncat and wcsncat.
Looks good to me.
> ---
> manual/string.texi | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/manual/string.texi b/manual/string.texi
> index 3329761..1e45d9d 100644
> --- a/manual/string.texi
> +++ b/manual/string.texi
> @@ -955,8 +955,8 @@ The @code{strncat} function could be implemented like this:
> char *
> strncat (char *to, const char *from, size_t size)
> @{
> - to[strlen (to) + size] = '\0';
> - strncpy (to + strlen (to), from, size);
> + memcpy (to + strlen (to), from, strnlen (from, size));
> + to[strlen (to) + strnlen (from, size)] = '\0';
> return to;
> @}
> @end group
> @@ -982,8 +982,8 @@ wchar_t *
> wcsncat (wchar_t *restrict wto, const wchar_t *restrict wfrom,
> size_t size)
> @{
> - wto[wcslen (to) + size] = L'\0';
> - wcsncpy (wto + wcslen (wto), wfrom, size);
> + memcpy (wto + wcslen (wto), wfrom, wcsnlen (wfrom, size) * sizeof (wchar_t));
> + wto[wcslen (to) + wcsnlen (wfrom, size)] = '\0';
> return wto;
> @}
> @end group
>
Cheers,
Carlos.