← Commit list

4a79224cf

Ron Yorston
Ron Yorston
2016-01-31
SUCCESS Duration: 259s

Subject

printf: short-circuit output when argument to %b includes \c

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

coreutils/printf.c+9 -3
@@ -131,8 +131,8 @@ static double my_xstrtod(const char *arg)
return result;
}
-/* Handles %b */
-static void print_esc_string(const char *str)
+/* Handles %b; return 1 if output is to be short-circuited by \c */
+static int print_esc_string(const char *str)
{
char c;
while ((c = *str) != '\0') {
@@ -145,6 +145,9 @@ static void print_esc_string(const char *str)
str++;
}
}
+ else if (*str == 'c') {
+ return 1;
+ }
{
/* optimization: don't force arg to be on-stack,
* use another variable for that. */
@@ -155,6 +158,8 @@ static void print_esc_string(const char *str)
}
putchar(c);
}
+
+ return 0;
}
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 (*argv) {
- print_esc_string(*argv);
+ if (print_esc_string(*argv))
+ return saved_argv; /* causes main() to exit */
++argv;
}
break;