diff options
Diffstat (limited to 'manual/string.texi')
-rw-r--r-- | manual/string.texi | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/manual/string.texi b/manual/string.texi index 4f276a95ae..8f0f5fa1d2 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 |