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