From 6d85e0c68ea66576816c612552d0093fa3aab408 Mon Sep 17 00:00:00 2001 From: Syed Faaiz Date: Tue, 8 Oct 2024 08:19:10 -0700 Subject: [PATCH] Add romaric's suggestion back in Co-authored-by: Romaric Jodin --- src/printf.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/printf.cpp b/src/printf.cpp index 619e8644..235edff8 100644 --- a/src/printf.cpp +++ b/src/printf.cpp @@ -187,16 +187,14 @@ void process_printf(char*& data, const printf_descriptor_map_t& descs, // Handle special cases if (part_end == part_start + 1) { printf_out << "%"; - size_t next_format = format_string.find_first_of('%', part_end + 1); - // Check if there is anything to print between two % - if (next_format != std::string::npos && - next_format - part_end > 1) { - // Print everything in between the two % - printf_out << format_string.substr( - part_end + 1, next_format - (part_end + 1)); - next_part = next_format; - } else { - next_part = part_end + 1; + // We also need to print the literals between '%%' and the next '%' + next_part = part_start = part_end + 1; + part_end = format_string.find_first_of('%', part_start); + if (part_end != std::string::npos && part_end > part_start) { + part_fmt = + format_string.substr(part_start, part_end - part_start); + printf_out << part_fmt; + next_part = part_end; } continue; } else if (part_end == std::string::npos &&