summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2020-07-22 16:28:46 +1000
committerDamien George <damien@micropython.org>2020-07-22 16:29:54 +1000
commitd9b726102429f555aec12275bb740f315ae9a795 (patch)
tree6c5649457b95d7279a4273b20e96b352ceaa94a6 /lib/libc
parent27767aafa21754e6cdbf52a719e7ce395f0fe672 (diff)
lib/libc: Fix string0's implementation of strncpy.
Fixing 98e583430fb7b793119db27bad9f98119e81579f, the semantics of strncpy require that the remainder of dst be filled with null bytes. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'lib/libc')
-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;
}
}