summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libc/string0.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/libc/string0.c b/lib/libc/string0.c
index 5f40a71e3..19ad14d0f 100644
--- a/lib/libc/string0.c
+++ b/lib/libc/string0.c
@@ -178,8 +178,10 @@ char *strncpy(char *s1, const char *s2, size_t n) {
while (n > 0) {
n--;
if ((*dst++ = *src++) == '\0') {
- /* If we get here, we found a null character at the end of s2 */
- *dst = '\0';
+ /* If we get here, we found a null character at the end
+ of s2, so use memset to put null bytes at the end of
+ s1. */
+ memset(dst, '\0', n);
break;
}
}