From patchwork Fri Dec 4 23:33:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Eggert X-Patchwork-Id: 9902 Received: (qmail 129763 invoked by alias); 4 Dec 2015 23:33:05 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 129753 invoked by uid 89); 4 Dec 2015 23:33:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL, BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: zimbra.cs.ucla.edu To: GNU C Library development From: Paul Eggert Subject: [PATCH] Fix typo in strncat, wcsncat manual entries Message-ID: <566222AD.3010901@cs.ucla.edu> Date: Fri, 4 Dec 2015 15:33:01 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 Committed as obvious. @end group @@ -1025,8 +1026,9 @@ wchar_t * wcsncat (wchar_t *restrict wto, const wchar_t *restrict wfrom, size_t size) @{ - memcpy (wto + wcslen (wto), wfrom, wcsnlen (wfrom, size) * sizeof (wchar_t)); - wto[wcslen (to) + wcsnlen (wfrom, size)] = '\0'; + size_t len = wcslen (wto); + memcpy (wto + len, wfrom, wcsnlen (wfrom, size) * sizeof (wchar_t)); + wto[len + wcsnlen (wfrom, size)] = L'\0'; return wto; @} @end group From 42b44bde21c234229a145b2d70c11466513c178e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 4 Dec 2015 15:23:18 -0800 Subject: [PATCH] Fix typo in strncat, wcsncat manual entries * manual/string.texi (Copying and Concatenation): Fix typos in sample implementations of strncat and wcsncat, by having them use the old value of the destination length, not the new one. --- ChangeLog | 7 +++++++ manual/string.texi | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index edd7ccf..379ba75 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2015-12-04 Paul Eggert + + Fix typo in strncat, wcsncat manual entries + * manual/string.texi (Copying and Concatenation): Fix typos in + sample implementations of strncat and wcsncat, by having them use + the old value of the destination length, not the new one. + 2015-12-04 Joseph Myers [BZ #16961] diff --git a/manual/string.texi b/manual/string.texi index 4f276a9..8f0f5fa 100644 --- a/manual/string.texi +++ b/manual/string.texi @@ -996,8 +996,9 @@ The @code{strncat} function could be implemented like this: char * strncat (char *to, const char *from, size_t size) @{ - memcpy (to + strlen (to), from, strnlen (from, size)); - to[strlen (to) + strnlen (from, size)] = '\0'; + size_t len = strlen (to); + memcpy (to + len, from, strnlen (from, size)); + to[len + strnlen (from, size)] = '\0'; return to; @} @end group @@ -1025,8 +1026,9 @@ wchar_t * wcsncat (wchar_t *restrict wto, const wchar_t *restrict wfrom, size_t size) @{ - memcpy (wto + wcslen (wto), wfrom, wcsnlen (wfrom, size) * sizeof (wchar_t)); - wto[wcslen (to) + wcsnlen (wfrom, size)] = '\0'; + size_t len = wcslen (wto); + memcpy (wto + len, wfrom, wcsnlen (wfrom, size) * sizeof (wchar_t)); + wto[len + wcsnlen (wfrom, size)] = L'\0'; return wto; @} @end group -- 2.1.0