LIB: Fix % escape condition
When using % to escape another %, the logic was incorrect as there was
no check on whether the formatting flag was set. Therefore a second %
would end up being ignored. Fix the logic by moving the % check inside
the formatting bool check thus allowing an escaped % to be printed.
Change-Id: If83a3c018182d1c43d6e66ad95b594e4ed278253
Signed-off-by: Jackson Cooper-Driver <jackson.cooper-driver@arm.com>
diff --git a/lib/tfm_vprintf/src/tfm_vprintf.c b/lib/tfm_vprintf/src/tfm_vprintf.c
index 4120f10..3d4abd9 100644
--- a/lib/tfm_vprintf/src/tfm_vprintf.c
+++ b/lib/tfm_vprintf/src/tfm_vprintf.c
@@ -103,18 +103,17 @@
bool zero_padding = false;
while ((c = *fmt++) != '\0') {
- if (c == '%') {
- zero_padding = false;
- num_padding = 0;
- formatting = true;
- continue;
- }
-
if (!formatting) {
- if (c == '\n') {
- output_char(output_func, priv, '\r');
+ if (c == '%') {
+ zero_padding = false;
+ num_padding = 0;
+ formatting = true;
+ } else {
+ if (c == '\n') {
+ output_char(output_func, priv, '\r');
+ }
+ output_char(output_func, priv, c);
}
- output_char(output_func, priv, c);
continue;
}