]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
printf: Fix and test %% behaviour in presence of subsequenbt args.
authorVladimir Serbinenko <phcoder@gmail.com>
Fri, 12 Feb 2016 11:33:41 +0000 (12:33 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Fri, 12 Feb 2016 11:33:41 +0000 (12:33 +0100)
grub-core/kern/misc.c
tests/printf_unit_test.c

index 906d2c2f7b174e1a24b062b402cba67cc0bc22e3..e3f8516339f951f2260fc47945d617d4e9ade5e5 100644 (file)
@@ -740,6 +740,12 @@ parse_printf_args (const char *fmt0, struct printf_args *args,
        fmt++;
 
       c = *fmt++;
+      if (c == '%')
+       {
+         n--;
+         continue;
+       }
+
       if (c == 'l')
        {
          c = *fmt++;
@@ -876,6 +882,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
       if (c == '%')
        {
          write_char (str, &count, max_len,c);
+         n--;
          continue;
        }
 
index eb76bd00220f11b4c527b1556077db0141e3fa7b..d7b12c6dbee6e84ace9d9f81d476622194810b26 100644 (file)
@@ -66,6 +66,9 @@ printf_test (void)
   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);
   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);