diff options
| author | Paul Eggert | 2017-06-01 16:03:12 -0700 |
|---|---|---|
| committer | Paul Eggert | 2017-06-01 16:06:38 -0700 |
| commit | 8de2581a64dac3785fc3877f7cd87c4164fd2936 (patch) | |
| tree | af8885c43a57dee86b17c05118a78d6f1d0361ac /src | |
| parent | 178d0cb5f530e6d7eb36eb9987ff405c854ccdb3 (diff) | |
| download | emacs-8de2581a64dac3785fc3877f7cd87c4164fd2936.tar.gz emacs-8de2581a64dac3785fc3877f7cd87c4164fd2936.zip | |
Limit format fields to more POSIX-like spec
* doc/lispref/strings.texi (Formatting Strings):
Don’t allow mixing numbered with unnumbered format specs.
* src/editfns.c (styled_format): Don’t bother checking for field 0,
since it doesn’t crash and the behavior is not specified.
* test/src/editfns-tests.el (format-with-field): Adjust tests to
match current doc. Add more tests for out-of-range fields.
Diffstat (limited to 'src')
| -rw-r--r-- | src/editfns.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/editfns.c b/src/editfns.c index 1dbae8f5d4b..29af25aab4f 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -3900,8 +3900,10 @@ where field is [0-9]+ followed by a literal dollar "$", flags is | |||
| 3900 | [+ #-0]+, width is [0-9]+, and precision is a literal period "." | 3900 | [+ #-0]+, width is [0-9]+, and precision is a literal period "." |
| 3901 | followed by [0-9]+. | 3901 | followed by [0-9]+. |
| 3902 | 3902 | ||
| 3903 | If field is given, it must be a one-based argument number; the given | 3903 | If a %-sequence is numbered with a field with positive value N, the |
| 3904 | argument is substituted instead of the next one. | 3904 | Nth argument is substituted instead of the next one. A format can |
| 3905 | contain either numbered or unnumbered %-sequences but not both, except | ||
| 3906 | that %% can be mixed with numbered %-sequences. | ||
| 3905 | 3907 | ||
| 3906 | The + flag character inserts a + before any positive number, while a | 3908 | The + flag character inserts a + before any positive number, while a |
| 3907 | space inserts a space before any positive number; these flags only | 3909 | space inserts a space before any positive number; these flags only |
| @@ -4081,8 +4083,6 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message) | |||
| 4081 | num = str2num (format, &num_end); | 4083 | num = str2num (format, &num_end); |
| 4082 | if (*num_end == '$') | 4084 | if (*num_end == '$') |
| 4083 | { | 4085 | { |
| 4084 | if (num == 0) | ||
| 4085 | error ("Invalid format field number 0"); | ||
| 4086 | n = num - 1; | 4086 | n = num - 1; |
| 4087 | format = num_end + 1; | 4087 | format = num_end + 1; |
| 4088 | } | 4088 | } |