aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2020-05-16 22:23:28 -0700
committerPaul Eggert2020-05-16 22:25:07 -0700
commit313955110b242cd18fc19bd168032d3ddf39fe94 (patch)
tree4292cf3b216b6a76e5c28e3841c2f6fa2f56caf3
parent1fc4e3fb3f6caba6a4ca69060c7992ea5d24ff36 (diff)
downloademacs-313955110b242cd18fc19bd168032d3ddf39fe94.tar.gz
emacs-313955110b242cd18fc19bd168032d3ddf39fe94.zip
Don’t attempt to modify constant strings
* 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.
-rw-r--r--lisp/bookmark.el2
-rw-r--r--lisp/button.el2
-rw-r--r--lisp/password-cache.el2
-rw-r--r--lisp/progmodes/elisp-mode.el14
-rw-r--r--test/lisp/emacs-lisp/cl-macs-tests.el4
-rw-r--r--test/lisp/erc/erc-track-tests.el4
-rw-r--r--test/lisp/password-cache-tests.el14
7 files changed, 21 insertions, 21 deletions
diff --git a/lisp/bookmark.el b/lisp/bookmark.el
index 0fa77ed3224..5bb16981711 100644
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -1723,7 +1723,7 @@ deletion, or > if it is flagged for displaying."
1723;; according to `bookmark-bookmarks-timestamp'. 1723;; according to `bookmark-bookmarks-timestamp'.
1724(defun bookmark-bmenu-set-header () 1724(defun bookmark-bmenu-set-header ()
1725 "Set the immutable header line." 1725 "Set the immutable header line."
1726 (let ((header (concat "%% " "Bookmark"))) 1726 (let ((header (copy-sequence "%% Bookmark")))
1727 (when bookmark-bmenu-toggle-filenames 1727 (when bookmark-bmenu-toggle-filenames
1728 (setq header (concat header 1728 (setq header (concat header
1729 (make-string (- bookmark-bmenu-file-column 1729 (make-string (- bookmark-bmenu-file-column
diff --git a/lisp/button.el b/lisp/button.el
index 3a6a6de774c..f969a03cb02 100644
--- a/lisp/button.el
+++ b/lisp/button.el
@@ -349,7 +349,7 @@ Also see `insert-text-button'."
349 (or (plist-member properties 'type) 349 (or (plist-member properties 'type)
350 (plist-member properties :type)))) 350 (plist-member properties :type))))
351 (when (stringp beg) 351 (when (stringp beg)
352 (setq object beg beg 0 end (length object))) 352 (setq object (copy-sequence beg) beg 0 end (length object)))
353 ;; Disallow setting the `category' property directly. 353 ;; Disallow setting the `category' property directly.
354 (when (plist-get properties 'category) 354 (when (plist-get properties 'category)
355 (error "Button `category' property may not be set directly")) 355 (error "Button `category' property may not be set directly"))
diff --git a/lisp/password-cache.el b/lisp/password-cache.el
index 5e5f3240bc3..86d802f283c 100644
--- a/lisp/password-cache.el
+++ b/lisp/password-cache.el
@@ -31,7 +31,7 @@
31;; ;; Minibuffer prompt for password. 31;; ;; Minibuffer prompt for password.
32;; => "foo" 32;; => "foo"
33;; 33;;
34;; (password-cache-add "test" "foo") 34;; (password-cache-add "test" (copy-sequence "foo"))
35;; => nil 35;; => nil
36 36
37;; (password-read "Password? " "test") 37;; (password-read "Password? " "test")
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index b737134f90c..d37eb8c152d 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -655,18 +655,16 @@ functions are annotated with \"<f>\" via the
655;; WORKAROUND: This is nominally a constant, but the text properties 655;; WORKAROUND: This is nominally a constant, but the text properties
656;; are not preserved thru dump if use defconst. See bug#21237. 656;; are not preserved thru dump if use defconst. See bug#21237.
657(defvar elisp--xref-format 657(defvar elisp--xref-format
658 (let ((str "(%s %s)")) 658 #("(%s %s)"
659 (put-text-property 1 3 'face 'font-lock-keyword-face str) 659 1 3 (face font-lock-keyword-face)
660 (put-text-property 4 6 'face 'font-lock-function-name-face str) 660 4 6 (face font-lock-function-name-face)))
661 str))
662 661
663;; WORKAROUND: This is nominally a constant, but the text properties 662;; WORKAROUND: This is nominally a constant, but the text properties
664;; are not preserved thru dump if use defconst. See bug#21237. 663;; are not preserved thru dump if use defconst. See bug#21237.
665(defvar elisp--xref-format-extra 664(defvar elisp--xref-format-extra
666 (let ((str "(%s %s %s)")) 665 #("(%s %s %s)"
667 (put-text-property 1 3 'face 'font-lock-keyword-face str) 666 1 3 (face font-lock-keyword-face)
668 (put-text-property 4 6 'face 'font-lock-function-name-face str) 667 4 6 (face font-lock-function-name-face)))
669 str))
670 668
671(defvar find-feature-regexp);; in find-func.el 669(defvar find-feature-regexp);; in find-func.el
672 670
diff --git a/test/lisp/emacs-lisp/cl-macs-tests.el b/test/lisp/emacs-lisp/cl-macs-tests.el
index 983e79ac57c..24bbad0cc6b 100644
--- a/test/lisp/emacs-lisp/cl-macs-tests.el
+++ b/test/lisp/emacs-lisp/cl-macs-tests.el
@@ -425,7 +425,9 @@ collection clause."
425 '(2 3 4 5 6)))) 425 '(2 3 4 5 6))))
426 426
427(ert-deftest cl-macs-loop-across-ref () 427(ert-deftest cl-macs-loop-across-ref ()
428 (should (equal (cl-loop with my-vec = ["one" "two" "three"] 428 (should (equal (cl-loop with my-vec = (vector (cl-copy-seq "one")
429 (cl-copy-seq "two")
430 (cl-copy-seq "three"))
429 for x across-ref my-vec 431 for x across-ref my-vec
430 do (setf (aref x 0) (upcase (aref x 0))) 432 do (setf (aref x 0) (upcase (aref x 0)))
431 finally return my-vec) 433 finally return my-vec)
diff --git a/test/lisp/erc/erc-track-tests.el b/test/lisp/erc/erc-track-tests.el
index 7e924c22347..457f08cb73c 100644
--- a/test/lisp/erc/erc-track-tests.el
+++ b/test/lisp/erc/erc-track-tests.el
@@ -107,8 +107,8 @@
107 107
108(ert-deftest erc-track--erc-faces-in () 108(ert-deftest erc-track--erc-faces-in ()
109 "`erc-faces-in' should pick up both 'face and 'font-lock-face properties." 109 "`erc-faces-in' should pick up both 'face and 'font-lock-face properties."
110 (let ((str0 "is bold") 110 (let ((str0 (copy-sequence "is bold"))
111 (str1 "is bold")) 111 (str1 (copy-sequence "is bold")))
112 ;; Turn on Font Lock mode: this initialize `char-property-alias-alist' 112 ;; Turn on Font Lock mode: this initialize `char-property-alias-alist'
113 ;; to '((face font-lock-face)). Note that `font-lock-mode' don't 113 ;; to '((face font-lock-face)). Note that `font-lock-mode' don't
114 ;; turn on the mode if the test is run on batch mode or if the 114 ;; turn on the mode if the test is run on batch mode or if the
diff --git a/test/lisp/password-cache-tests.el b/test/lisp/password-cache-tests.el
index 01f4358fc59..55ebbfce7fe 100644
--- a/test/lisp/password-cache-tests.el
+++ b/test/lisp/password-cache-tests.el
@@ -28,31 +28,31 @@
28 28
29(ert-deftest password-cache-tests-add-and-remove () 29(ert-deftest password-cache-tests-add-and-remove ()
30 (let ((password-data (copy-hash-table password-data))) 30 (let ((password-data (copy-hash-table password-data)))
31 (password-cache-add "foo" "bar") 31 (password-cache-add "foo" (copy-sequence "bar"))
32 (should (eq (password-in-cache-p "foo") t)) 32 (should (eq (password-in-cache-p "foo") t))
33 (password-cache-remove "foo") 33 (password-cache-remove "foo")
34 (should (not (password-in-cache-p "foo"))))) 34 (should (not (password-in-cache-p "foo")))))
35 35
36(ert-deftest password-cache-tests-read-from-cache () 36(ert-deftest password-cache-tests-read-from-cache ()
37 (let ((password-data (copy-hash-table password-data))) 37 (let ((password-data (copy-hash-table password-data)))
38 (password-cache-add "foo" "bar") 38 (password-cache-add "foo" (copy-sequence "bar"))
39 (should (equal (password-read-from-cache "foo") "bar")) 39 (should (equal (password-read-from-cache "foo") "bar"))
40 (should (not (password-read-from-cache nil))))) 40 (should (not (password-read-from-cache nil)))))
41 41
42(ert-deftest password-cache-tests-in-cache-p () 42(ert-deftest password-cache-tests-in-cache-p ()
43 (let ((password-data (copy-hash-table password-data))) 43 (let ((password-data (copy-hash-table password-data)))
44 (password-cache-add "foo" "bar") 44 (password-cache-add "foo" (copy-sequence "bar"))
45 (should (password-in-cache-p "foo")) 45 (should (password-in-cache-p "foo"))
46 (should (not (password-read-from-cache nil))))) 46 (should (not (password-read-from-cache nil)))))
47 47
48(ert-deftest password-cache-tests-read () 48(ert-deftest password-cache-tests-read ()
49 (let ((password-data (copy-hash-table password-data))) 49 (let ((password-data (copy-hash-table password-data)))
50 (password-cache-add "foo" "bar") 50 (password-cache-add "foo" (copy-sequence "bar"))
51 (should (equal (password-read nil "foo") "bar")))) 51 (should (equal (password-read nil "foo") "bar"))))
52 52
53(ert-deftest password-cache-tests-reset () 53(ert-deftest password-cache-tests-reset ()
54 (let ((password-data (copy-hash-table password-data))) 54 (let ((password-data (copy-hash-table password-data)))
55 (password-cache-add "foo" "bar") 55 (password-cache-add "foo" (copy-sequence "bar"))
56 (password-reset) 56 (password-reset)
57 (should (not (password-in-cache-p "foo"))))) 57 (should (not (password-in-cache-p "foo")))))
58 58
@@ -60,14 +60,14 @@
60 :tags '(:expensive-test) 60 :tags '(:expensive-test)
61 (let ((password-data (copy-hash-table password-data)) 61 (let ((password-data (copy-hash-table password-data))
62 (password-cache-expiry 0.01)) 62 (password-cache-expiry 0.01))
63 (password-cache-add "foo" "bar") 63 (password-cache-add "foo" (copy-sequence "bar"))
64 (sit-for 0.1) 64 (sit-for 0.1)
65 (should (not (password-in-cache-p "foo"))))) 65 (should (not (password-in-cache-p "foo")))))
66 66
67(ert-deftest password-cache-tests-no-password-cache () 67(ert-deftest password-cache-tests-no-password-cache ()
68 (let ((password-data (copy-hash-table password-data)) 68 (let ((password-data (copy-hash-table password-data))
69 (password-cache nil)) 69 (password-cache nil))
70 (password-cache-add "foo" "bar") 70 (password-cache-add "foo" (copy-sequence "bar"))
71 (should (not (password-in-cache-p "foo"))) 71 (should (not (password-in-cache-p "foo")))
72 (should (not (password-read-from-cache "foo"))))) 72 (should (not (password-read-from-cache "foo")))))
73 73