diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-11-12 07:36:15 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-11-12 07:36:15 -0600 |
commit | d0c76ccacf0dc8988f9617ad82bf4349f456bb08 (patch) | |
tree | dff6dde66182f380b40c6982d28ad40b1bf33be3 /nuttx/libc | |
parent | 948af9557a2876e13e3faabd6c387b8c91a4d144 (diff) | |
download | nuttx-d0c76ccacf0dc8988f9617ad82bf4349f456bb08.tar.gz nuttx-d0c76ccacf0dc8988f9617ad82bf4349f456bb08.tar.bz2 nuttx-d0c76ccacf0dc8988f9617ad82bf4349f456bb08.zip |
The definition of strncpy() is that empty space should be zero-filled, the patch adds the zero filling (I didn’t know this, see e.g. the POSIX spec here: http://pubs.opengroup.org/onlinepubs/7908799/xsh/strncpy.html). From Lorenz Meier.
Diffstat (limited to 'nuttx/libc')
-rw-r--r-- | nuttx/libc/string/lib_strncpy.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/nuttx/libc/string/lib_strncpy.c b/nuttx/libc/string/lib_strncpy.c index a6bbf7ad1..bd9de57a1 100644 --- a/nuttx/libc/string/lib_strncpy.c +++ b/nuttx/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 |