Skip to content

Commit

Permalink
clean up printf
Browse files Browse the repository at this point in the history
printf is avoiding switch statements so that it can be used in
very early startup, before jump tables can be read from the F segment.
We could use -fno-jump-tables, but we can also keep the if statements
and clean them up so that the indentation is fine.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
bonzini committed Jul 24, 2019
1 parent 0f14738 commit f8d4dd2
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions printf.c
Expand Up @@ -157,18 +157,17 @@ int vsnprintf(char *buf, int size, const char *fmt, va_list va)
}
morefmt:
f = *fmt++;
do {
if (f == '%') {
addchar(&s, '%');
break;
continue;
}
if (f == 'c') {
addchar(&s, va_arg(va, int));
break;
continue;
}
if (f == '\0') {
--fmt;
break;
continue;
}
if (f == '0') {
props.pad = '0';
Expand Down Expand Up @@ -196,7 +195,7 @@ int vsnprintf(char *buf, int size, const char *fmt, va_list va)
panic();
break;
}
break;
continue;
}
if (f == 'x') {
switch (nlong) {
Expand All @@ -210,20 +209,18 @@ int vsnprintf(char *buf, int size, const char *fmt, va_list va)
panic();
break;
}
break;
continue;
}
if (f == 'p') {
print_str(&s, "0x", props);
print_unsigned(&s, (unsigned long)va_arg(va, void *), 16, props);
break;
continue;
}
if (f == 's') {
print_str(&s, va_arg(va, const char *), props);
break;
continue;
}
addchar(&s, f);
break;
} while(0);
}
*s.buffer = 0;
++s.added;
Expand Down

0 comments on commit f8d4dd2

Please sign in to comment.