diff options
Diffstat (limited to 'libc/manual/string.texi')
-rw-r--r-- | libc/manual/string.texi | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/libc/manual/string.texi b/libc/manual/string.texi index 2a164a952..1e45d9ddb 100644 --- a/libc/manual/string.texi +++ b/libc/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 @@ -1370,7 +1370,7 @@ int compare_elements (const void *v1, const void *v2) @{ char * const *p1 = v1; - char * const *p1 = v2; + char * const *p2 = v2; return strcoll (*p1, *p2); @} |