]> git.eshelyaron.com Git - emacs.git/commitdiff
Don’t attempt to modify constant strings
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 17 May 2020 05:23:28 +0000 (22:23 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 17 May 2020 05:25:07 +0000 (22:25 -0700)
* lisp/bookmark.el (bookmark-bmenu-set-header):
Use copy-sequence instead of concat, for clarity.
Also, the byte-compiler optimizes (concat "a" "b") into "ab".
* lisp/button.el (make-text-button):
* test/lisp/erc/erc-track-tests.el (erc-track--erc-faces-in):
* test/lisp/password-cache-tests.el:
(password-cache-tests-add-and-remove)
(password-cache-tests-read-from-cache)
(password-cache-tests-in-cache-p, password-cache-tests-read)
(password-cache-tests-reset)
(password-cache-tests-add/expires-key)
(password-cache-tests-no-password-cache):
Don’t attempt to modify constant strings.
* lisp/progmodes/elisp-mode.el (elisp--xref-format)
(elisp--xref-format-extra):
Don’t attempt to modify constant strings via put-text-property.
* test/lisp/emacs-lisp/cl-macs-tests.el (cl-macs-loop-across-ref):
Don’t attempt to modify constant vectors or strings.

lisp/bookmark.el
lisp/button.el
lisp/password-cache.el
lisp/progmodes/elisp-mode.el
test/lisp/emacs-lisp/cl-macs-tests.el
test/lisp/erc/erc-track-tests.el
test/lisp/password-cache-tests.el

index 0fa77ed32246b796e14fc5f2999f0bddbdd39f88..5bb16981711a26c152b9a8d39a145a4ee144c529 100644 (file)
@@ -1723,7 +1723,7 @@ deletion, or > if it is flagged for displaying."
 ;; according to `bookmark-bookmarks-timestamp'.
 (defun bookmark-bmenu-set-header ()
   "Set the immutable header line."
-  (let ((header (concat "%% " "Bookmark")))
+  (let ((header (copy-sequence "%% Bookmark")))
     (when bookmark-bmenu-toggle-filenames
       (setq header (concat header
                           (make-string (- bookmark-bmenu-file-column
index 3a6a6de774c8d612cbf00bbc614ceb3594bc6496..f969a03cb028f5c807c9e6ea4fbf179f215d16f7 100644 (file)
@@ -349,7 +349,7 @@ Also see `insert-text-button'."
         (or (plist-member properties 'type)
             (plist-member properties :type))))
     (when (stringp beg)
-      (setq object beg beg 0 end (length object)))
+      (setq object (copy-sequence beg) beg 0 end (length object)))
     ;; Disallow setting the `category' property directly.
     (when (plist-get properties 'category)
       (error "Button `category' property may not be set directly"))
index 5e5f3240bc38400171be5c63ea5442c32efa18e3..86d802f283c27b258951c1363a3bff8ab2e7ea9c 100644 (file)
@@ -31,7 +31,7 @@
 ;; ;; Minibuffer prompt for password.
 ;;  => "foo"
 ;;
-;; (password-cache-add "test" "foo")
+;; (password-cache-add "test" (copy-sequence "foo"))
 ;;  => nil
 
 ;; (password-read "Password? " "test")
index b737134f90c5451109e9f8c47718bdc81504b03c..d37eb8c152dae04c72d43e536d1bd150ac431e74 100644 (file)
@@ -655,18 +655,16 @@ functions are annotated with \"<f>\" via the
 ;; WORKAROUND: This is nominally a constant, but the text properties
 ;; are not preserved thru dump if use defconst.  See bug#21237.
 (defvar elisp--xref-format
-  (let ((str "(%s %s)"))
-    (put-text-property 1 3 'face 'font-lock-keyword-face str)
-    (put-text-property 4 6 'face 'font-lock-function-name-face str)
-    str))
+  #("(%s %s)"
+    1 3 (face font-lock-keyword-face)
+    4 6 (face font-lock-function-name-face)))
 
 ;; WORKAROUND: This is nominally a constant, but the text properties
 ;; are not preserved thru dump if use defconst.  See bug#21237.
 (defvar elisp--xref-format-extra
-  (let ((str "(%s %s %s)"))
-    (put-text-property 1 3 'face 'font-lock-keyword-face str)
-    (put-text-property 4 6 'face 'font-lock-function-name-face str)
-    str))
+  #("(%s %s %s)"
+    1 3 (face font-lock-keyword-face)
+    4 6 (face font-lock-function-name-face)))
 
 (defvar find-feature-regexp);; in find-func.el
 
index 983e79ac57c6f6297ce28c638bf51bc627620ffb..24bbad0cc6b5e3d4da9116b12f72280d330dd8d9 100644 (file)
@@ -425,7 +425,9 @@ collection clause."
                  '(2 3 4 5 6))))
 
 (ert-deftest cl-macs-loop-across-ref ()
-  (should (equal (cl-loop with my-vec = ["one" "two" "three"]
+  (should (equal (cl-loop with my-vec = (vector (cl-copy-seq "one")
+                                                (cl-copy-seq "two")
+                                                (cl-copy-seq "three"))
                           for x across-ref my-vec
                           do (setf (aref x 0) (upcase (aref x 0)))
                           finally return my-vec)
index 7e924c22347ad75d0c5324320fad13d51f505880..457f08cb73c029300cfa00ccb441bee1a1f785a1 100644 (file)
 
 (ert-deftest erc-track--erc-faces-in ()
   "`erc-faces-in' should pick up both 'face and 'font-lock-face properties."
-  (let ((str0 "is bold")
-        (str1 "is bold"))
+  (let ((str0 (copy-sequence "is bold"))
+        (str1 (copy-sequence "is bold")))
     ;; Turn on Font Lock mode: this initialize `char-property-alias-alist'
     ;; to '((face font-lock-face)).  Note that `font-lock-mode' don't
     ;; turn on the mode if the test is run on batch mode or if the
index 01f4358fc590de3a499b39d609d33b443b9575bf..55ebbfce7fe18fb82b02aacdca51aac3a7e717b2 100644 (file)
 
 (ert-deftest password-cache-tests-add-and-remove ()
   (let ((password-data (copy-hash-table password-data)))
-    (password-cache-add "foo" "bar")
+    (password-cache-add "foo" (copy-sequence "bar"))
     (should (eq (password-in-cache-p "foo") t))
     (password-cache-remove "foo")
     (should (not (password-in-cache-p "foo")))))
 
 (ert-deftest password-cache-tests-read-from-cache ()
   (let ((password-data (copy-hash-table password-data)))
-    (password-cache-add "foo" "bar")
+    (password-cache-add "foo" (copy-sequence "bar"))
     (should (equal (password-read-from-cache "foo") "bar"))
     (should (not (password-read-from-cache nil)))))
 
 (ert-deftest password-cache-tests-in-cache-p ()
   (let ((password-data (copy-hash-table password-data)))
-    (password-cache-add "foo" "bar")
+    (password-cache-add "foo" (copy-sequence "bar"))
     (should (password-in-cache-p "foo"))
     (should (not (password-read-from-cache nil)))))
 
 (ert-deftest password-cache-tests-read ()
   (let ((password-data (copy-hash-table password-data)))
-    (password-cache-add "foo" "bar")
+    (password-cache-add "foo" (copy-sequence "bar"))
     (should (equal (password-read nil "foo") "bar"))))
 
 (ert-deftest password-cache-tests-reset ()
   (let ((password-data (copy-hash-table password-data)))
-    (password-cache-add "foo" "bar")
+    (password-cache-add "foo" (copy-sequence "bar"))
     (password-reset)
     (should (not (password-in-cache-p "foo")))))
 
   :tags '(:expensive-test)
   (let ((password-data (copy-hash-table password-data))
         (password-cache-expiry 0.01))
-    (password-cache-add "foo" "bar")
+    (password-cache-add "foo" (copy-sequence "bar"))
     (sit-for 0.1)
     (should (not (password-in-cache-p "foo")))))
 
 (ert-deftest password-cache-tests-no-password-cache ()
   (let ((password-data (copy-hash-table password-data))
         (password-cache nil))
-    (password-cache-add "foo" "bar")
+    (password-cache-add "foo" (copy-sequence "bar"))
     (should (not (password-in-cache-p "foo")))
     (should (not (password-read-from-cache "foo")))))