GNU bug report logs - #79621
31.0.50; rx macro fails an obvious sanity test (match index off by one)

Previous Next

Package: emacs;

Reported by: Lockywolf <for_emacs_1 <at> lockywolf.net>

Date: Tue, 14 Oct 2025 09:19:03 UTC

Severity: normal

Found in version 31.0.50

Done: Lockywolf <for_emacs_1 <at> lockywolf.net>

To reply to this bug, email your comments to 79621 AT debbugs.gnu.org.
There is no need to reopen the bug first.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#79621; Package emacs. (Tue, 14 Oct 2025 09:19:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Lockywolf <for_emacs_1 <at> lockywolf.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 14 Oct 2025 09:19:04 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Lockywolf <for_emacs_1 <at> lockywolf.net>
To: bug-gnu-emacs <at> gnu.org
Subject: 31.0.50; rx macro fails an obvious sanity test (match index off by
 one)
Date: Tue, 14 Oct 2025 17:18:07 +0800
[Message part 1 (text/plain, inline)]
(with-temp-buffer
  (insert "hello Emacs world")
  (string-match (rx (group (+ anychar))
                    (group "Emacs"))
                (buffer-string))
 (match-string 1))
=>
(args-out-of-range #<buffer  *temp*> 0 6)

In fact, args should be 1 and 7, not 0 and 6.


In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.31, cairo version 1.16.0) of 2025-09-27 built on
 laptop.lockywolf.net
Repository revision: 339003c9db6a4d48734f199e955e2d9caa26a8f8
Repository branch: ispell-tests-2
Windowing system distributor 'The X.Org Foundation', version 11.0.12014000
System Description: Slackware 15.0 x86_64

Configured using:
 'configure 'CC=ccache gcc'
 PKG_CONFIG_PATH=/opt/cuda-12.6/usr/lib64/pkgconfig/:/opt/cuda-12.6/usr/lib64/pkgconfig/:/opt/cuda-12.6/usr/lib64/pkgconfig/::/usr/local/lib64/pkgconfig:/usr/local/share/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/share/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/share/pkgconfig'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND
SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM
XINERAMA XINPUT2 XPM XRANDR GTK3 ZLIB

Important settings:
  value of $LC_COLLATE: C
  value of $LC_TIME: en_GB.UTF-8
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-nonselected-mode: t
  minibuffer-regexp-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug lisp-mnt message mailcap yank-media puny
dired dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg
rfc6068 epg-config gnus-util text-property-search time-date subr-x
mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr
mail-utils help-fns radix-tree cl-print byte-opt gv bytecomp
byte-compile debug backtrace help-mode find-func rx warnings icons
cl-loaddefs cl-lib rmc iso-transl tooltip cconv eldoc paren electric
uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/x-win x-win term/common-win x-dnd touch-screen tool-bar dnd fontset
image regexp-opt fringe tabulated-list replace newcomment text-mode
lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch
easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo gtk
x-toolkit xinput2 x multi-tty move-toolbar make-network-process
tty-child-frames emacs)

Memory information:
((conses 16 55798 9505) (symbols 48 6818 0) (strings 32 17100 1779)
 (string-bytes 1 440015) (vectors 16 12339)
 (vector-slots 8 136277 10985) (floats 8 24 9) (intervals 56 512 0)
 (buffers 1064 13))


[Message part 2 (text/plain, inline)]
-- 
Your sincerely,
Vladimir Nikishkin (MiEr, lockywolf)
(Laptop)
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79621; Package emacs. (Tue, 14 Oct 2025 09:53:01 GMT) Full text and rfc822 format available.

Message #8 received at 79621 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Lockywolf <for_emacs_1 <at> lockywolf.net>
Cc: 79621 <at> debbugs.gnu.org
Subject: Re: bug#79621: 31.0.50; rx macro fails an obvious sanity test
 (match index off by one)
Date: Tue, 14 Oct 2025 11:53:52 +0200
Lockywolf <for_emacs_1 <at> lockywolf.net> writes:

> (with-temp-buffer
>   (insert "hello Emacs world")
>   (string-match (rx (group (+ anychar))
>                     (group "Emacs"))
>                 (buffer-string))
>  (match-string 1))
> =>
> (args-out-of-range #<buffer  *temp*> 0 6)
>
> In fact, args should be 1 and 7, not 0 and 6.

Your problem is not about `rx', since specifying the regexp in string
form leads to the same result:

#+begin_src emacs-lisp
(with-temp-buffer
  (insert "hello Emacs world")
  (string-match "\\([^z-a]+\\)\\(Emacs\\)"
                (buffer-string))
 (match-string 1))
#+end_src

Please note this paragraph in (info "(elisp) Simple Match Data"):

|  -- Function: match-string count &optional in-string
|    [...]
|    If the last such operation was done against a string with
|    ‘string-match’, then you should pass the same string as the
|    argument IN-STRING.  After a buffer search or match, you should
|    omit IN-STRING or pass ‘nil’ for it; but you should make sure that
|    the current buffer when you call ‘match-string’ is the one in which
|    you did the searching or matching.  Failure to follow this advice
|    will lead to incorrect results.

So your call is just wrong, you have to pass the string used for
matching.


Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79621; Package emacs. (Tue, 14 Oct 2025 09:55:02 GMT) Full text and rfc822 format available.

Message #11 received at 79621 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Lockywolf <for_emacs_1 <at> lockywolf.net>
Cc: 79621 <at> debbugs.gnu.org
Subject: Re: bug#79621: 31.0.50; rx macro fails an obvious sanity test
 (match index off by one)
Date: Tue, 14 Oct 2025 11:53:50 +0200
>>>>> On Tue, 14 Oct 2025 17:18:07 +0800, Lockywolf <for_emacs_1 <at> lockywolf.net> said:

    Lockywolf> (with-temp-buffer
    Lockywolf>   (insert "hello Emacs world")
    Lockywolf>   (string-match (rx (group (+ anychar))
    Lockywolf>                     (group "Emacs"))
    Lockywolf>                 (buffer-string))
    Lockywolf>  (match-string 1))
    Lockywolf> =>
    Lockywolf> (args-out-of-range #<buffer  *temp*> 0 6)

    Lockywolf> In fact, args should be 1 and 7, not 0 and 6.

This is nothing to do with rx. When you call `match-string' after
`string-match' you have to pass the string again.

Robert
-- 




Reply sent to Lockywolf <for_emacs_1 <at> lockywolf.net>:
You have taken responsibility. (Tue, 14 Oct 2025 11:02:02 GMT) Full text and rfc822 format available.

Notification sent to Lockywolf <for_emacs_1 <at> lockywolf.net>:
bug acknowledged by developer. (Tue, 14 Oct 2025 11:02:02 GMT) Full text and rfc822 format available.

Message #16 received at 79621-done <at> debbugs.gnu.org (full text, mbox):

From: Lockywolf <for_emacs_1 <at> lockywolf.net>
To: 79621-done <at> debbugs.gnu.org
Subject: Re: bug#79621: Acknowledgement (31.0.50; rx macro fails an obvious
 sanity test (match index off by one))
Date: Tue, 14 Oct 2025 19:01:42 +0800
match-string should be called with the second argument

-- 
Your sincerely,
Vladimir Nikishkin (MiEr, lockywolf)
(Laptop)




This bug report was last modified 23 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.