printf: short-circuit output when argument to %b includes \c
printf wasn't correctly handling \c in an argument to the %b format specifier. printf %bXX OK\\c returned 'OK\cXX' rather than the expected 'OK'. function old new delta printf_main 886 899 +13 Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
2a4bba3ce2
commit
4a79224cfc
@ -131,8 +131,8 @@ static double my_xstrtod(const char *arg)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handles %b */
|
/* Handles %b; return 1 if output is to be short-circuited by \c */
|
||||||
static void print_esc_string(const char *str)
|
static int print_esc_string(const char *str)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
while ((c = *str) != '\0') {
|
while ((c = *str) != '\0') {
|
||||||
@ -145,6 +145,9 @@ static void print_esc_string(const char *str)
|
|||||||
str++;
|
str++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (*str == 'c') {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
{
|
{
|
||||||
/* optimization: don't force arg to be on-stack,
|
/* optimization: don't force arg to be on-stack,
|
||||||
* use another variable for that. */
|
* use another variable for that. */
|
||||||
@ -155,6 +158,8 @@ static void print_esc_string(const char *str)
|
|||||||
}
|
}
|
||||||
putchar(c);
|
putchar(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_direc(char *format, unsigned fmt_length,
|
static void print_direc(char *format, unsigned fmt_length,
|
||||||
@ -280,7 +285,8 @@ static char **print_formatted(char *f, char **argv, int *conv_err)
|
|||||||
}
|
}
|
||||||
if (*f == 'b') {
|
if (*f == 'b') {
|
||||||
if (*argv) {
|
if (*argv) {
|
||||||
print_esc_string(*argv);
|
if (print_esc_string(*argv))
|
||||||
|
return saved_argv; /* causes main() to exit */
|
||||||
++argv;
|
++argv;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user