]> git.corax.cc Git - corax/commitdiff
libc, kernel/klibc: Fix bug in snprintf() that would cause the wrong string length...
authorMatthias Kruk <m@m10k.eu>
Sun, 26 Jul 2020 08:12:19 +0000 (17:12 +0900)
committerMatthias Kruk <m@m10k.eu>
Sun, 26 Jul 2020 08:12:19 +0000 (17:12 +0900)
kernel/klibc/stdio.c
libc/stdio.c

index 7674e4007fd41b3e0ca6244363a182233e874fc5..302226cfca75eb1847cd31109b610db46eaa68d6 100644 (file)
@@ -358,8 +358,10 @@ int _convert_str(char *dst, int precision, int padlen, const char *src)
        slen = strlen(src);
        padlen -= slen;
 
-       while(precision-- > 0 && padlen-- > 0) {
+       while(precision > 0 && padlen > 0) {
                dst[ret_val++] = ' ';
+               precision--;
+               padlen--;
        }
 
        /* precision may still be larger than slen */
index 7313ff6e2dd2b574b325bde19dc5f81314d7eb6f..fbd9a90c929cc625cdc9b70daea0d33a2e87853e 100644 (file)
@@ -20,6 +20,8 @@
 #define FLAG_LCHEX   (1 << 6)
 #define FLAG_USIGN   (1 << 7)
 
+extern void* memcpy2(void*, const void*, size_t);
+
 static int _convert_oct(char *dst, int flags, int precision, int width, int padlen, void *data)
 {
        union {
@@ -348,8 +350,10 @@ static int _convert_str(char *dst, int precision, int padlen, const char *src)
        slen = strlen(src);
        padlen -= slen;
 
-       while(precision-- > 0 && padlen-- > 0) {
+       while(precision > 0 && padlen > 0) {
                dst[ret_val++] = ' ';
+               precision--;
+               padlen--;
        }
 
        /* precision may still be larger than slen */