]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix typo in strncat, wcsncat manual entries
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 4 Dec 2015 23:23:18 +0000 (15:23 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 4 Dec 2015 23:24:35 +0000 (15:24 -0800)
* 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
manual/string.texi

index edd7ccf33a5fdbc1411480f96bb0589ea668e33d..379ba75ee1ae1680e77cade913cdea972aa904db 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2015-12-04  Paul Eggert  <eggert@cs.ucla.edu>
+
+       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  <joseph@codesourcery.com>
 
        [BZ #16961]
index 4f276a95aeb8b401c017dfc13b6e76bb376299c9..8f0f5fa1d2cb9b020eb7b8ef77cbb95d4f571f18 100644 (file)
@@ -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