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 <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30574>
(cherry picked from commit 4080269845)
This commit is contained in:
Karol Herbst 2024-08-08 19:21:54 +02:00 committed by Eric Engestrom
parent 4af40c1d25
commit 6fca3cd058
2 changed files with 4 additions and 5 deletions

View file

@ -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

View file

@ -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];