From cabd22f5c6c2f47b1f6efd627e9e760a31e8f015 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sat, 21 Aug 2021 15:24:15 +0200 Subject: Make parse-partial-sexp signal an error if TO is smaller than FROM * src/syntax.c (Fparse_partial_sexp): Signal an error if TO is smaller than FROM (bug#49944). --- src/syntax.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/syntax.c') diff --git a/src/syntax.c b/src/syntax.c index 7bba336744a..6cbe0f6855f 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -3547,8 +3547,10 @@ DEFUN ("parse-partial-sexp", Fparse_partial_sexp, Sparse_partial_sexp, 2, 6, 0, doc: /* Parse Lisp syntax starting at FROM until TO; return status of parse at TO. Parsing stops at TO or when certain criteria are met; point is set to where parsing stops. -If fifth arg OLDSTATE is omitted or nil, - parsing assumes that FROM is the beginning of a function. + +If OLDSTATE is omitted or nil, parsing assumes that FROM is the + beginning of a function. If not, OLDSTATE should be the state at + FROM. Value is a list of elements describing final state of parsing: 0. depth in parens. @@ -3594,6 +3596,9 @@ Sixth arg COMMENTSTOP non-nil means stop after the start of a comment. else target = TYPE_MINIMUM (EMACS_INT); /* We won't reach this depth. */ + if (XFIXNUM (to) < XFIXNUM (from)) + error ("End position should be larger than start position."); + validate_region (&from, &to); internalize_parse_state (oldstate, &state); scan_sexps_forward (&state, XFIXNUM (from), CHAR_TO_BYTE (XFIXNUM (from)), -- cgit v1.2.3 From 5da710344392ac59a814b8841d31a562823737f0 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sat, 21 Aug 2021 16:07:44 +0200 Subject: Tweak the comment-start-skip example in the manual * doc/emacs/programs.texi (Options for Comments): Tweak the example regexp for comment-start-skip (bug#15006). --- doc/emacs/programs.texi | 12 ++++++------ src/syntax.c | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/syntax.c') diff --git a/doc/emacs/programs.texi b/doc/emacs/programs.texi index fe3ee57ac0a..09216c278b1 100644 --- a/doc/emacs/programs.texi +++ b/doc/emacs/programs.texi @@ -1098,13 +1098,13 @@ match the last comment before point in the buffer, and then does a expression that is the value of the variable @code{comment-start-skip}. Make sure this regexp does not match the null string. It may match more than the comment starting delimiter in the strictest sense of the word; -for example, in C mode the value of the variable is +for example, in C mode the value of the variable could be @c This stops M-q from breaking the line inside that @code. -@code{@w{"\\(//+\\|/\\*+\\)\\s *"}}, which matches extra stars and -spaces after the @samp{/*} itself, and accepts C++ style comments -also. (Note that @samp{\\} is needed in Lisp syntax to include a -@samp{\} in the string, which is needed to deny the first star its -special meaning in regexp syntax. @xref{Regexp Backslash}.) +@code{@w{"/\\*+[ \t]*\\|//+[ \t]*"}}, which matches extra stars and +spaces after the @samp{/*} itself, and accepts C++ style (@samp{//}) +comments also. (Note that @samp{\\} is needed in Lisp syntax to +include a @samp{\} in the string, which is needed to deny the first +star its special meaning in regexp syntax. @xref{Regexp Backslash}.) @vindex comment-start @vindex comment-end diff --git a/src/syntax.c b/src/syntax.c index 6cbe0f6855f..1ef4a712281 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -17,6 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ +// foo #include -- cgit v1.2.3 From 964151570b0acb889765d4e973db2fba229ae59e Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 21 Aug 2021 17:13:46 +0300 Subject: ; * src/syntax.c: Remove a stray comment. --- src/syntax.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/syntax.c') diff --git a/src/syntax.c b/src/syntax.c index 1ef4a712281..adc0da730ea 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -17,8 +17,6 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ -// foo - #include #include "lisp.h" -- cgit v1.2.3 From ff2124d2979ee9ba5b8e22147fa8ccaa00e2cc4f Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Sat, 21 Aug 2021 22:55:58 +0100 Subject: Fix recent parse-partial-sexp argument validation * src/syntax.c (parse-partial-sexp): Also handle markers as arguments (bug#49944). Tweak error message to follow conventions in "(elisp) Signaling Errors". --- src/syntax.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/syntax.c') diff --git a/src/syntax.c b/src/syntax.c index adc0da730ea..057a4c3b1f5 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -3595,8 +3595,8 @@ Sixth arg COMMENTSTOP non-nil means stop after the start of a comment. else target = TYPE_MINIMUM (EMACS_INT); /* We won't reach this depth. */ - if (XFIXNUM (to) < XFIXNUM (from)) - error ("End position should be larger than start position."); + if (fix_position (to) < fix_position (from)) + error ("End position is smaller than start position"); validate_region (&from, &to); internalize_parse_state (oldstate, &state); -- cgit v1.2.3