Commit d9b72610 authored by Damien George's avatar Damien George

lib/libc: Fix string0's implementation of strncpy.

Fixing 98e58343, the semantics of strncpy
require that the remainder of dst be filled with null bytes.
Signed-off-by: default avatarDamien George <damien@micropython.org>
parent 27767aaf
...@@ -178,8 +178,10 @@ char *strncpy(char *s1, const char *s2, size_t n) { ...@@ -178,8 +178,10 @@ char *strncpy(char *s1, const char *s2, size_t n) {
while (n > 0) { while (n > 0) {
n--; n--;
if ((*dst++ = *src++) == '\0') { if ((*dst++ = *src++) == '\0') {
/* If we get here, we found a null character at the end of s2 */ /* If we get here, we found a null character at the end
*dst = '\0'; of s2, so use memset to put null bytes at the end of
s1. */
memset(dst, '\0', n);
break; break;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment