From 554f56b99dd4e85404e9954da4498351e7d170a1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 11 Dec 2014 06:21:23 -0600 Subject: [PATCH] strncpy: Commit d0c76ccacf0dc8988f9617ad82bf4349f456bb08 will trash a lot of memory if n == 0. From Hiro --- libc/string/lib_strncpy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/string/lib_strncpy.c b/libc/string/lib_strncpy.c index bd9de57a1d..bba16a0a3b 100644 --- a/libc/string/lib_strncpy.c +++ b/libc/string/lib_strncpy.c @@ -55,7 +55,7 @@ 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++ = *src++) != '\0' && dest != end); + while ((dest != end) && (*dest++ = *src++) != '\0'); while (dest != end) *dest++ = '\0'; return ret; }