Subject: Re: bug#49944: parse-partial-sexp fails to signal an error when (> START LIMIT).

From: "Basil L. Contovounesios" <[email-masked]>
Date: Sat, 21 Aug 2021 23:11:55 +0100

Lars Ingebrigtsen [2021-08-21 15:24 +0200] wrote:

> Alan Mackenzie <[email-masked]> writes:
>
>> Emacs-28, emacs started with site-start.el and .emacs.
>>
>> On calling
>>
>>     (parse-partial-sexp 19 18 nil nil s)
>>
>> Emacs surely ought to signal an error, since 18 < 19.  It doesn't,
>> though.  It leaves point at a random position and returns
>>
>>     (0 nil nil nil nil nil 0 nil nil nil nil)
>>
>> This is a bug.
>
> I've now made this change (and the doc string clarification discussed).
> There are no test failures after the change, and I'm not getting any
> errors when running it normally, either.

Found one :).

0. emacs -Q
1. M-x toggle-debug-on-error RET
2. M-x ielm RET RET

Debugger entered--Lisp error:
    (error "End position should be larger than start position.")
  parse-partial-sexp(#<marker at 64 in *ielm*> 64)
  ielm-return()
  funcall-interactively(ielm-return)
  call-interactively(ielm-return nil nil)
  command-execute(ielm-return)

One option is to replace XFIXNUM with fix_position, which is what the
subsequent validate_region also does.  Another option is to
CHECK_FIXNUM_COERCE_MARKER before the comparison.  Any preference?

>From 34c87c83fa86263da863da6c0a920c746b8af02b Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <[email-masked]>
Date: Sat, 21 Aug 2021 22:55:58 +0100
Subject: [PATCH] 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(-)

diff --git a/src/syntax.c b/src/syntax.c
index adc0da730e..057a4c3b1f 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -3595,8 +3595,8 @@ DEFUN ("parse-partial-sexp", Fparse_partial_sexp, Sparse_partial_sexp, 2, 6, 0,
   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);
-- 
2.32.0

Thanks,

-- 
Basil