GNU bug report logs - #79057
30.1; `split-string` unexpectedly clears match data when called on an unrelated string.

Previous Next

Package: emacs;

Reported by: Jennifer and Navid Madani <jnmadani <at> hotmail.com>

Date: Sun, 20 Jul 2025 10:51:02 UTC

Severity: normal

Tags: notabug

Found in version 30.1

Done: Eli Zaretskii <eliz <at> gnu.org>

Full log


View this message in rfc822 format

From: Eli Zaretskii <eliz <at> gnu.org>
To: Jennifer and Navid Madani <jnmadani <at> hotmail.com>
Cc: 79057 <at> debbugs.gnu.org
Subject: bug#79057: 30.1; `split-string` unexpectedly clears match data when called on an unrelated string.
Date: Sun, 20 Jul 2025 15:05:41 +0300
tags 79057 notabug
thanks

> From: Jennifer and Navid Madani <jnmadani <at> hotmail.com>
> Date: Sun, 20 Jul 2025 00:44:20 +0000
> 
> Run test1 in the code snippet below for reproducing the bug.
> 
> I tested it using emacs -Q on macOS and Ubuntu with the same result.
> 
> 
> (setq *MULTI-LAB-ENTRY-RE* "^\\([[:alpha:]]\\)?[[:space:]]?\\([[:digit:]]\\{2\\}/[[:digit:]]\\{2\\}/[[:digit:]]\\{4\\}\\)[[:space:]]+\\([[:digit:]]\\{2\\}:[[:digit:]]\\{2\\}\\)[[:space:]]+\\(.+\\)")
> 
> 
> (defun test1 ()
>   (let ((line "a 05/22/2025 14:32 BLOOD WBC 10.4 H K/uL 4.5 - 10.0"))
>     (string-match *MULTI-LAB-ENTRY-RE* line)
>     (message "match-data after string-match: %S" (match-data))
>     (split-string "dummy string") ;; Do NOT pass 'line' here
>     (message "match-data after split-string: %S" (match-data))
>     (message "group 1: %S" (match-string 1))))
> 
> (test1)

It isn't a bug: any Emacs function can modify match-data, unless its
doc string explicitly says it doesn't.  And in this case, the doc
string even takes extra care to say it does:

  Modifies the match data; use ‘save-match-data’ if necessary.

You need to change your code to use save-match-data.




This bug report was last modified 24 days ago.

Previous Next


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