diff options
| author | Eli Zaretskii | 2020-09-19 19:54:01 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2020-09-19 19:54:01 +0300 |
| commit | df04f3e755f3001ebb9cc428faa7fa46059e636b (patch) | |
| tree | acf478dc8aca3749f10ad6f9d5527cc29b05ed4c | |
| parent | fd1fe1e1ecb6c68bbdea4bf071166779388174d0 (diff) | |
| download | emacs-df04f3e755f3001ebb9cc428faa7fa46059e636b.tar.gz emacs-df04f3e755f3001ebb9cc428faa7fa46059e636b.zip | |
Fix a rare segfault in syntax.c
* src/syntax.c (Fforward_comment): Prevent the loop for COUNT < 0
from going outside the valid range of character/byte positions.
(Bug#43499)
* doc/lispref/syntax.texi (Syntax Class Table): Mention the
"comment-fence" and "string-fence" as alternative names of 2
syntax classes.
| -rw-r--r-- | doc/lispref/syntax.texi | 18 | ||||
| -rw-r--r-- | src/syntax.c | 25 |
2 files changed, 24 insertions, 19 deletions
diff --git a/doc/lispref/syntax.texi b/doc/lispref/syntax.texi index b3c77665bae..b99b5de0b31 100644 --- a/doc/lispref/syntax.texi +++ b/doc/lispref/syntax.texi | |||
| @@ -256,10 +256,11 @@ look in the standard syntax table to find the syntax of this | |||
| 256 | character. | 256 | character. |
| 257 | 257 | ||
| 258 | @item Generic comment delimiters: @samp{!} | 258 | @item Generic comment delimiters: @samp{!} |
| 259 | Characters that start or end a special kind of comment. @emph{Any} | 259 | (This syntax class is also known as ``comment-fence''.) Characters |
| 260 | generic comment delimiter matches @emph{any} generic comment | 260 | that start or end a special kind of comment. @emph{Any} generic |
| 261 | delimiter, but they cannot match a comment starter or comment ender; | 261 | comment delimiter matches @emph{any} generic comment delimiter, but |
| 262 | generic comment delimiters can only match each other. | 262 | they cannot match a comment starter or comment ender; generic comment |
| 263 | delimiters can only match each other. | ||
| 263 | 264 | ||
| 264 | This syntax class is primarily meant for use with the | 265 | This syntax class is primarily meant for use with the |
| 265 | @code{syntax-table} text property (@pxref{Syntax Properties}). You | 266 | @code{syntax-table} text property (@pxref{Syntax Properties}). You |
| @@ -268,10 +269,11 @@ first and last characters of the range @code{syntax-table} properties | |||
| 268 | identifying them as generic comment delimiters. | 269 | identifying them as generic comment delimiters. |
| 269 | 270 | ||
| 270 | @item Generic string delimiters: @samp{|} | 271 | @item Generic string delimiters: @samp{|} |
| 271 | Characters that start or end a string. This class differs from the | 272 | (This syntax class is also known as ``string-fence''.) Characters |
| 272 | string quote class in that @emph{any} generic string delimiter can | 273 | that start or end a string. This class differs from the string quote |
| 273 | match any other generic string delimiter; but they do not match | 274 | class in that @emph{any} generic string delimiter can match any other |
| 274 | ordinary string quote characters. | 275 | generic string delimiter; but they do not match ordinary string quote |
| 276 | characters. | ||
| 275 | 277 | ||
| 276 | This syntax class is primarily meant for use with the | 278 | This syntax class is primarily meant for use with the |
| 277 | @code{syntax-table} text property (@pxref{Syntax Properties}). You | 279 | @code{syntax-table} text property (@pxref{Syntax Properties}). You |
diff --git a/src/syntax.c b/src/syntax.c index a79ab863367..e8b32f5a445 100644 --- a/src/syntax.c +++ b/src/syntax.c | |||
| @@ -2545,20 +2545,23 @@ between them, return t; otherwise return nil. */) | |||
| 2545 | bool fence_found = 0; | 2545 | bool fence_found = 0; |
| 2546 | ptrdiff_t ini = from, ini_byte = from_byte; | 2546 | ptrdiff_t ini = from, ini_byte = from_byte; |
| 2547 | 2547 | ||
| 2548 | while (1) | 2548 | if (from > stop) |
| 2549 | { | 2549 | { |
| 2550 | DEC_BOTH (from, from_byte); | 2550 | while (1) |
| 2551 | UPDATE_SYNTAX_TABLE_BACKWARD (from); | ||
| 2552 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); | ||
| 2553 | if (SYNTAX (c) == Scomment_fence | ||
| 2554 | && !char_quoted (from, from_byte)) | ||
| 2555 | { | 2551 | { |
| 2556 | fence_found = 1; | 2552 | DEC_BOTH (from, from_byte); |
| 2557 | break; | 2553 | UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 2554 | c = FETCH_CHAR_AS_MULTIBYTE (from_byte); | ||
| 2555 | if (SYNTAX (c) == Scomment_fence | ||
| 2556 | && !char_quoted (from, from_byte)) | ||
| 2557 | { | ||
| 2558 | fence_found = 1; | ||
| 2559 | break; | ||
| 2560 | } | ||
| 2561 | else if (from == stop) | ||
| 2562 | break; | ||
| 2563 | rarely_quit (++quit_count); | ||
| 2558 | } | 2564 | } |
| 2559 | else if (from == stop) | ||
| 2560 | break; | ||
| 2561 | rarely_quit (++quit_count); | ||
| 2562 | } | 2565 | } |
| 2563 | if (fence_found == 0) | 2566 | if (fence_found == 0) |
| 2564 | { | 2567 | { |