From 639641dc04746be57a6385be8b2b0e76bc8d7c2e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 12 Nov 2014 07:36:15 -0600 Subject: [PATCH] =?UTF-8?q?The=20definition=20of=20strncpy()=20is=20that?= =?UTF-8?q?=20empty=20space=20should=20be=20zero-filled,=20the=20patch=20a?= =?UTF-8?q?dds=20the=20zero=20filling=20(I=20didn=E2=80=99t=20know=20this,?= =?UTF-8?q?=20see=20e.g.=20the=20POSIX=20spec=20here:=20http://pubs.opengr?= =?UTF-8?q?oup.org/onlinepubs/7908799/xsh/strncpy.html).=20From=20Lorenz?= =?UTF-8?q?=20Meier.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libc/string/lib_strncpy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libc/string/lib_strncpy.c b/libc/string/lib_strncpy.c index a6bbf7ad1c..bd9de57a1d 100644 --- a/libc/string/lib_strncpy.c +++ b/libc/string/lib_strncpy.c @@ -55,7 +55,8 @@ char *strncpy(FAR char *dest, FAR const char *src, size_t n) char *ret = dest; /* Value to be returned */ char *end = dest + n; /* End of dest buffer + 1 byte */ - while (dest != end && (*dest++ = *src++) != '\0'); + while ((*dest++ = *src++) != '\0' && dest != end); + while (dest != end) *dest++ = '\0'; return ret; } #endif