From 0cc1fb53d5b9baae0f985a06b1aad4d121d81831 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 aa7dee2470..81db60ae28 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; }