From 6fca3cd058426dbadb4c6e80511a4a54121d59e4 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Thu, 8 Aug 2024 19:21:54 +0200 Subject: [PATCH] util/u_printf: do not double print format string with unused arugments the CL CTS added a new test being printf("\n", "foo"), but we ended up printing the new line twice. If we can't find a specifier anymore, ignore the argument as after the loop processing all arguments we'll print the remaining format string anyway. Cc: mesa-stable Reviewed-by: Jesse Natalie Part-of: (cherry picked from commit 408026984551665562ce95260b92fd7db7f49c71) --- .pick_status.json | 2 +- src/util/u_printf.c | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index fce08739e5f..2d7ad9fc2a5 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1384,7 +1384,7 @@ "description": "util/u_printf: do not double print format string with unused arugments", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/util/u_printf.c b/src/util/u_printf.c index 09c4b98071b..5422b158b97 100644 --- a/src/util/u_printf.c +++ b/src/util/u_printf.c @@ -166,10 +166,9 @@ u_printf_impl(FILE *out, const char *buffer, size_t buffer_size, int arg_size = fmt->arg_sizes[i]; size_t spec_pos = util_printf_next_spec_pos(format, 0); - if (spec_pos == -1) { - u_printf_plain(out, format); - continue; - } + /* If we hit an unused argument we skip all remaining ones */ + if (spec_pos == -1) + break; const char *token = util_printf_prev_tok(&format[spec_pos]); const char *next_format = &format[spec_pos + 1];