Subject: bug#78690: closed (Re: bug#78690: 31.0.50; split string: args out of range with TRIM)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 21 Jun 2025 08:14:02 +0000

Your bug report

#78690: 31.0.50; split string: args out of range with TRIM

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
78690: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=78690
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#78690: 31.0.50; split string: args out of range with TRIM
From: Eli Zaretskii <[email-masked]>
To: Michael Heerdegen <[email-masked]>
Cc: [email-masked]
Date: Sat, 21 Jun 2025 11:13:36 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Michael Heerdegen <[email-masked]>
> Cc: [email-masked]
> Date: Thu, 19 Jun 2025 19:43:31 +0200
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > If you tell me what is confusing or unclear, I will try to clarify
> > that.  I guess after staring at the code as much as I did, I've lost
> > the ability to see the confusing parts, beyond the comments I added
> > that you saw in the patch.
> 
> The comments are actually good.  I got a bit confused because of the
> non-functional programming style (the helper lambda `push-one' changes
> state that is not local to that helper function), but... it's ok, it's
> just a complicated semantics being implemented so it takes some time to
> see what is going on where here.  All good.  Along with the comments one
> can make the way through the code.

Thanks, now installed on the master branch, and closing the bug.

Subject: 31.0.50; split string: args out of range with TRIM
From: Michael Heerdegen <[email-masked]>
To: [email-masked]
Date: Wed, 04 Jun 2025 04:36:26 +0200
List-Id: <debbugs-submit.debbugs.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)))))
|   (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'