]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* grub-core/kern/misc.c (grub_vsnprintf_real): Handle %% properly.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Tue, 15 Oct 2013 13:12:15 +0000 (15:12 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Tue, 15 Oct 2013 13:12:15 +0000 (15:12 +0200)
* tests/printf_unit_test.c (printf_test): Add %% tests.
Reported by: Paulo Flabiano Smorigo.

ChangeLog
grub-core/kern/misc.c
tests/printf_unit_test.c

index 4e7e4d982bd14fb986ad9c3a4bc8ee888c3fc652..628fb543463d574cb5266e3be4a3e6ac737e3775 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-10-15  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       * grub-core/kern/misc.c (grub_vsnprintf_real): Handle %% properly.
+       * tests/printf_unit_test.c (printf_test): Add %% tests.
+       Reported by: Paulo Flabiano Smorigo.
+
 2013-10-15  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/osdep/windows/hostdisk.c (fsync) [__MINGW32__]: Really
index 94b88a386d7b45988083e6caa9c5fa0f019290d7..027bfde9202153adce505804f4d5ec632ee0ea7f 100644 (file)
@@ -910,6 +910,12 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0, va_list a
            }
        }
 
+      if (c == '%')
+       {
+         write_char (c);
+         continue;
+       }
+
       if (curn >= count_args)
        continue;
 
index 3d2f8f15d324b14553df3b83b699fe63d20a9c81..b88c885949918fd0d3a775e214dd8903865132eb 100644 (file)
 #include <grub/test.h>
 #include <grub/misc.h>
 
-#define MSG "printf test failed"
+#define MSG "printf test failed: %s, %s", real, expected
 
 static void
 printf_test (void)
 {
   char real[512];
   char expected[512];
+
+  grub_snprintf (real, sizeof (real), "%d%%", 10);
+  snprintf (expected, sizeof (expected), "%d%%", 10);
+  grub_test_assert (strcmp (real, expected) == 0, MSG);
+
+  grub_snprintf (real, sizeof (real), "%d %%", 10);
+  snprintf (expected, sizeof (expected), "%d %%", 10);
+  grub_test_assert (strcmp (real, expected) == 0, MSG);
+
+  grub_snprintf (real, sizeof (real), "%%");
+  snprintf (expected, sizeof (expected), "%%");
+  grub_test_assert (strcmp (real, expected) == 0, MSG);
+
   grub_snprintf (real, sizeof (real), "%d %d %d", 1, 2, 3);
   snprintf (expected, sizeof (expected), "%d %d %d", 1, 2, 3);
   grub_test_assert (strcmp (real, expected) == 0, MSG);