Subject: bug#62847: 29.0.90; Propertized space in Org Agenda's mode-name

From: Mattias Engdegård <[email-masked]>
Date: Sat, 15 Apr 2023 15:15:12 +0200

15 apr. 2023 kl. 13.45 skrev Eli Zaretskii <[email-masked]>:
>>> So maybe replace " " with (copy-sequence " ").
>> 
>> But that should not be necessary, right?

Ideally not -- setting properties on literal strings should indeed be avoided for a variety of reasons, one being that the byte compiler shares equal string literals:

(defun ff ()
  (list "abc" (let ((s "abc"))
                (put-text-property 0 3 'aa 'bb s)
                s)))

(ff)
 -> ("abc" #("abc" 0 3 (aa bb)))                 ; interpreted
 -> (#("abc" 0 3 (aa bb)) #("abc" 0 3 (aa bb)))  ; byte-compiled

`org-agenda-set-mode-name` uses the literal " " twice so if either is modified the other will appear to be, too. Where this setting of properties is done I have no idea

There is currently no automatic sharing of string literals between byte-code functions but this may change, and I've no idea what the native compiler is up to in this respect.

`propertize` is safe because it makes a copy of its string argument, so there shouldn't be any reason to copy that argument explicitly.

`org-add-props` calls `add-text-properties` and is clearly destructive.

Interpreted code is less affected by the problem because literals aren't shared throughout a function, but trouble can still occur:

(defun hh (x)
  (let ((s "abc"))
    (when x
      (put-text-property 0 3 'aa 'bb s))
    s))

(hh nil) -> "abc"
(hh t)   -> #("abc" 0 3 (aa bb))
(hh nil) -> #("abc" 0 3 (aa bb))
...