From 5248a3fe48a6ad11d4b5f17b2b5e6a7db8f87e07 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 9 May 2023 20:30:12 +0300 Subject: [PATCH] LibC: Fix bug in *printf --- libc/stdio.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libc/stdio.cpp b/libc/stdio.cpp index aa7dee24..81db60ae 100644 --- a/libc/stdio.cpp +++ b/libc/stdio.cpp @@ -462,6 +462,10 @@ int vfprintf(FILE* file, const char* format, va_list arguments) switch (*format) { case '%': + if (fputc('%', file) == EOF) + return -1; + written++; + format++; break; case 's': { @@ -476,11 +480,15 @@ int vfprintf(FILE* file, const char* format, va_list arguments) break; } } - if (fputc(*format, file) == EOF) - return -1; - written++; - format++; + else + { + if (fputc(*format, file) == EOF) + return -1; + written++; + format++; + } } + return written; }