printf: Fix and test %% behaviour in presence of subsequenbt args.
This commit is contained in:
parent
d9a3bfead8
commit
e5c9300191
2 changed files with 10 additions and 0 deletions
|
@ -740,6 +740,12 @@ parse_printf_args (const char *fmt0, struct printf_args *args,
|
||||||
fmt++;
|
fmt++;
|
||||||
|
|
||||||
c = *fmt++;
|
c = *fmt++;
|
||||||
|
if (c == '%')
|
||||||
|
{
|
||||||
|
n--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (c == 'l')
|
if (c == 'l')
|
||||||
{
|
{
|
||||||
c = *fmt++;
|
c = *fmt++;
|
||||||
|
@ -876,6 +882,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
|
||||||
if (c == '%')
|
if (c == '%')
|
||||||
{
|
{
|
||||||
write_char (str, &count, max_len,c);
|
write_char (str, &count, max_len,c);
|
||||||
|
n--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,9 @@ printf_test (void)
|
||||||
grub_snprintf (real, sizeof (real), "%3$d %2$lld %1$d", 1, 2LL, 3);
|
grub_snprintf (real, sizeof (real), "%3$d %2$lld %1$d", 1, 2LL, 3);
|
||||||
snprintf (expected, sizeof (expected), "%3$d %2$lld %1$d", 1, 2LL, 3);
|
snprintf (expected, sizeof (expected), "%3$d %2$lld %1$d", 1, 2LL, 3);
|
||||||
grub_test_assert (strcmp (real, expected) == 0, MSG);
|
grub_test_assert (strcmp (real, expected) == 0, MSG);
|
||||||
|
grub_snprintf (real, sizeof (real), "%%0%dd ", 1);
|
||||||
|
snprintf (expected, sizeof (expected), "%%0%dd ", 1);
|
||||||
|
grub_test_assert (strcmp (real, expected) == 0, MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
GRUB_UNIT_TEST ("printf_unit_test", printf_test);
|
GRUB_UNIT_TEST ("printf_unit_test", printf_test);
|
||||||
|
|
Loading…
Reference in a new issue