commit cefb48011380150ac19e70ed7bfe1ac33dedd39c
Author:     Quentin Rameau <[email protected]>
AuthorDate: Fri Feb 17 00:21:50 2017 +0100
Commit:     Quentin Rameau <[email protected]>
CommitDate: Fri Feb 17 10:51:32 2017 +0100

    [libc] Fix strncpy
    
    Don't forget n is unsigned.

diff --git a/libc/src/strncpy.c b/libc/src/strncpy.c
index af3b41b..a1a1456 100644
--- a/libc/src/strncpy.c
+++ b/libc/src/strncpy.c
@@ -7,8 +7,8 @@ strncpy(char *dst, const char *src, size_t n)
 {
        char *ret = dst;
 
-       while (n-- > 0 && (*dst++ = *src++))
-               /* nothing */;
+       for (; n > 0 && *src; --n)
+               *dst++ = *src++;
        while (n-- > 0)
                *dst++ = '\0';
        return ret;

Reply via email to