GNU bug report logs -
#78690
31.0.50; split string: args out of range with TRIM
Previous Next
To reply to this bug, email your comments to 78690 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78690
; Package
emacs
.
(Wed, 04 Jun 2025 02:35:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Michael Heerdegen <michael_heerdegen <at> web.de>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Wed, 04 Jun 2025 02:35:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hello,
I stumbled across this:
#+begin_src emacs-lisp
(split-string
"-*- lexical-binding: t; -*-"
"-\\*-" nil "[ \t\n\r-]+")
#+end_src
~~>
| Debugger entered--Lisp error: (args-out-of-range "-*- lexical-binding: t; -*-" 1 0)
| (substring "-*- lexical-binding: t; -*-" 1 0)
| (let ((this (substring string this-start this-end))) (if trim (progn (let ((tem (string-match (concat trim "\\'") this 0))) (and tem (< tem (length this)) (setq this (substring this 0 tem)))))) (if (or keep-nulls (> (length this) 0)) (progn (setq list (cons this list)))))
| (progn (let ((this (substring string this-start this-end))) (if trim (progn (let ((tem (string-match ... this 0))) (and tem (< tem (length this)) (setq this (substring this 0 tem)))))) (if (or keep-nulls (> (length this) 0)) (progn (setq list (cons this list))))))
| (if (or keep-nulls (< this-start this-end)) (progn (let ((this (substring string this-start this-end))) (if trim (progn (let ((tem ...)) (and tem (< tem ...) (setq this ...))))) (if (or keep-nulls (> (length this) 0)) (progn (setq list (cons this list)))))))
| (#f(lambda () [(list nil) (this-end 0) (this-start 1) (keep-nulls t) (trim "[ \11\n\15-]+") (string "-*- lexical-binding: t; -*-")] (if trim (progn (let ((tem (string-match trim string this-start))) (and (eq tem this-start) (setq this-start (match-end 0)))))) (if (or keep-nulls (< this-start this-end)) (progn (let ((this (substring string this-start this-end))) (if trim (progn (let ... ...))) (if (or keep-nulls (> ... 0)) (progn (setq list ...))))))))
| (funcall #f(lambda () [(list nil) (this-end 0) (this-start 1) (keep-nulls t) (trim "[ \11\n\15-]+") (string "-*- lexical-binding: t; -*-")] (if trim (progn (let ((tem (string-match trim string this-start))) (and (eq tem this-start) (setq this-start (match-end 0)))))) (if (or keep-nulls (< this-start this-end)) (progn (let ((this (substring string this-start this-end))) (if trim (progn (let ... ...))) (if (or keep-nulls (> ... 0)) (progn (setq list ...))))))))
| (while (and (string-match rexp string (if (and notfirst (= start (match-beginning 0)) (< start (length string))) (1+ start) start)) (< start (length string))) (setq notfirst t) (progn (setq this-start start) (setq this-end (match-beginning 0)) (setq start (match-end 0))) (funcall push-one))
| (let* ((keep-nulls (not (if separators omit-nulls t))) (rexp (or separators split-string-default-separators)) (start 0) this-start this-end notfirst (list nil) (push-one #'(lambda nil (if trim (progn (let ... ...))) (if (or keep-nulls (< this-start this-end)) (progn (let ... ... ...)))))) (while (and (string-match rexp string (if (and notfirst (= start (match-beginning 0)) (< start (length string))) (1+ start) start)) (< start (length string))) (setq notfirst t) (progn (setq this-start start) (setq this-end (match-beginning 0)) (setq start (match-end 0))) (funcall push-one)) (progn (setq this-start start) (setq this-end (length string))) (funcall push-one) (nreverse list))
| (split-string "-*- lexical-binding: t; -*-" "-\\*-" nil "[ \11\n\15-]+")
No problem without TRIM arg in the call.
TIA,
Michael.
In GNU Emacs 31.0.50 (build 23, x86_64-pc-linux-gnu, cairo version
1.16.0) of 2025-06-03 built on drachen
Repository revision: 8e4a0ea35908e08c2220bafee33a05c33f24bbc3
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101007
System Description: Debian GNU/Linux 12 (bookworm)
Configured using:
'configure --with-x-toolkit=no --with-native-compilation=no'
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78690
; Package
emacs
.
(Thu, 05 Jun 2025 15:49:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 78690 <at> debbugs.gnu.org (full text, mbox):
> Date: Wed, 04 Jun 2025 04:36:26 +0200
> From: Michael Heerdegen via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>
>
> Hello,
>
> I stumbled across this:
>
> #+begin_src emacs-lisp
> (split-string
> "-*- lexical-binding: t; -*-"
> "-\\*-" nil "[ \t\n\r-]+")
> #+end_src
>
> ~~>
>
> | Debugger entered--Lisp error: (args-out-of-range "-*- lexical-binding: t; -*-" 1 0)
> | (substring "-*- lexical-binding: t; -*-" 1 0)
> | (let ((this (substring string this-start this-end))) (if trim (progn (let ((tem (string-match (concat trim "\\'") this 0))) (and tem (< tem (length this)) (setq this (substring this 0 tem)))))) (if (or keep-nulls (> (length this) 0)) (progn (setq list (cons this list)))))
It is quite obvious that split-string is not prepared to deal with a
situation where the argument STRING begins with a match for
SEPARATORS. The breakage here happens because the match for
SEPARATORS at the very beginning of STRING also matches TRIM, but even
if that is not so, a match for SEPARATORS at the beginning of STRING
sets THIS-START incorrectly for the first call to push-one inside the
while-loop.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78690
; Package
emacs
.
(Fri, 06 Jun 2025 01:53:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 78690 <at> debbugs.gnu.org (full text, mbox):
Eli Zaretskii <eliz <at> gnu.org> writes:
> It is quite obvious that split-string is not prepared to deal with a
> situation where the argument STRING begins with a match for
> SEPARATORS. The breakage here happens because the match for
> SEPARATORS at the very beginning of STRING also matches TRIM, but even
> if that is not so, a match for SEPARATORS at the beginning of STRING
> sets THIS-START incorrectly for the first call to push-one inside the
> while-loop.
I read that as "confirmed, a bug". Ok, thanks for the analysis.
The original use case is in Helm btw, which does a call like this. I
made the example a bit shorter for this report - in the original issue
the string starts with whitespace, like
" -*- lexical-binding: t; -*-"
but as you already mentioned the issue is the same.
Michael.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78690
; Package
emacs
.
(Fri, 06 Jun 2025 07:11:03 GMT)
Full text and
rfc822 format available.
Message #14 received at 78690 <at> debbugs.gnu.org (full text, mbox):
> From: Michael Heerdegen <michael_heerdegen <at> web.de>
> Cc: 78690 <at> debbugs.gnu.org
> Date: Fri, 06 Jun 2025 03:53:47 +0200
>
> Eli Zaretskii <eliz <at> gnu.org> writes:
>
> > It is quite obvious that split-string is not prepared to deal with a
> > situation where the argument STRING begins with a match for
> > SEPARATORS. The breakage here happens because the match for
> > SEPARATORS at the very beginning of STRING also matches TRIM, but even
> > if that is not so, a match for SEPARATORS at the beginning of STRING
> > sets THIS-START incorrectly for the first call to push-one inside the
> > while-loop.
>
> I read that as "confirmed, a bug". Ok, thanks for the analysis.
It's more than that: I'm working on this bug. It just takes time to
unlock all the subtleties of the implementation and understand how to
fix it in a most economical and safe way. I've just succeeded to
understand what was the root cause when I ran out of time.
The interim analysis was intended to attract others to the problem and
perhaps nudge someone to work out a solution. Also to serve a
reminder to myself when I get to look at this next time.
This bug report was last modified today.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.