diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | Src/utils.c | 3 | ||||
-rw-r--r-- | Src/zsh.h | 11 | ||||
-rw-r--r-- | Test/B03print.ztst | 5 |
4 files changed, 19 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog index 3eadca8f9..033e0b020 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-01-06 Barton E. Schaefer <schaefer@zsh.org> + + * 28578 (plus test): Src/utils.c, Src/zsh.h, Test/B03print.ztst: + fix handling of numeric escapes that expand to "%" in printf + format strings, so they are not treated as format introducers. + 2011-01-05 Peter Stephenson <p.w.stephenson@ntlworld.com> * 28568 c.f. 28549 (Ricky Zhou): Src/utils.c: buffer overflow @@ -14043,5 +14049,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5168 $ +* $Revision: 1.5169 $ ***************************************************** diff --git a/Src/utils.c b/Src/utils.c index a1cac2537..a4cd67812 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -1,4 +1,3 @@ - /* * utils.c - miscellaneous utilities * @@ -5523,6 +5522,8 @@ getkeystring(char *s, int *len, int how, int *misc) } *t++ = zstrtol(s + (*s == 'x'), &s, (*s == 'x') ? 16 : 8); + if ((how & GETKEY_PRINTF_PERCENT) && t[-1] == '%') + *t++ = '%'; if (svchar) { u[3] = svchar; svchar = '\0'; diff --git a/Src/zsh.h b/Src/zsh.h index 6dc918c09..6d8ac0353 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2492,7 +2492,11 @@ enum { * Yes, I know that doesn't seem to make much sense. * It's for use in completion, comprenez? */ - GETKEY_UPDATE_OFFSET = (1 << 7) + GETKEY_UPDATE_OFFSET = (1 << 7), + /* + * When replacing numeric escapes for printf format strings, % -> %% + */ + GETKEY_PRINTF_PERCENT = (1 << 8) }; /* @@ -2501,8 +2505,9 @@ enum { */ /* echo builtin */ #define GETKEYS_ECHO (GETKEY_BACKSLASH_C) -/* printf format string: \123 -> S, \0123 -> NL 3 */ -#define GETKEYS_PRINTF_FMT (GETKEY_OCTAL_ESC|GETKEY_BACKSLASH_C) +/* printf format string: \123 -> S, \0123 -> NL 3, \045 -> %% */ +#define GETKEYS_PRINTF_FMT \ + (GETKEY_OCTAL_ESC|GETKEY_BACKSLASH_C|GETKEY_PRINTF_PERCENT) /* printf argument: \123 -> \123, \0123 -> S */ #define GETKEYS_PRINTF_ARG (GETKEY_BACKSLASH_C) /* Full print without -e */ diff --git a/Test/B03print.ztst b/Test/B03print.ztst index 92a24d6b6..48574c227 100644 --- a/Test/B03print.ztst +++ b/Test/B03print.ztst @@ -105,10 +105,9 @@ 0:numeric value of high numbered character >f0 -# code will probably be changed to print the literal `%s' in this case printf '\x25s\n' arg -0:using \x25 to introduce a format specifier ->arg +0:using \x25 to print a literal % in format +>%s printf '%3c\n' c 0:width specified in format specifier |