summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2024-04-15 15:53:48 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2024-04-15 15:53:48 -0400
commit5fda398fb3bbda43dab37a0c187c90ad4bc4d1b0 (patch)
tree0fddfbee2fe64a790ff4d28778c698218a43245e /lisp/emacs-lisp
parent9b755244bf0b9cd5f820ae45a4db14913a587c7b (diff)
downloademacs-5fda398fb3bbda43dab37a0c187c90ad4bc4d1b0.tar.gz
(track-changes--before): Fix bug#70396
* lisp/emacs-lisp/track-changes.el (track-changes--before): Widen the buffer before accessing it with positions potentially outside the beg..end region.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/track-changes.el68
1 files changed, 34 insertions, 34 deletions
diff --git a/lisp/emacs-lisp/track-changes.el b/lisp/emacs-lisp/track-changes.el
index 1bab7ca38fd..df4aad0d596 100644
--- a/lisp/emacs-lisp/track-changes.el
+++ b/lisp/emacs-lisp/track-changes.el
@@ -481,42 +481,42 @@ Details logged to `track-changes--error-log'")
(funcall signal-if-disjoint end track-changes--before-beg)
(funcall signal-if-disjoint track-changes--before-end beg)))
(funcall reset))
- (cl-assert (save-restriction
- (widen)
- (<= (point-min)
+ (save-restriction
+ (widen)
+ (cl-assert (<= (point-min)
track-changes--before-beg
track-changes--before-end
- (point-max))))
- (when (< beg track-changes--before-beg)
- (if (and track-changes--disjoint-trackers
- (funcall signal-if-disjoint end track-changes--before-beg))
- (funcall reset)
- (let* ((old-bbeg track-changes--before-beg)
- ;; To avoid O(N²) behavior when faced with many small changes,
- ;; we copy more than needed.
- (new-bbeg (min (max (point-min)
- (- old-bbeg
- (length track-changes--before-string)))
- beg)))
- (setf track-changes--before-beg new-bbeg)
- (cl-callf (lambda (old new) (concat new old))
- track-changes--before-string
- (buffer-substring-no-properties new-bbeg old-bbeg)))))
-
- (when (< track-changes--before-end end)
- (if (and track-changes--disjoint-trackers
- (funcall signal-if-disjoint track-changes--before-end beg))
- (funcall reset)
- (let* ((old-bend track-changes--before-end)
- ;; To avoid O(N²) behavior when faced with many small changes,
- ;; we copy more than needed.
- (new-bend (max (min (point-max)
- (+ old-bend
- (length track-changes--before-string)))
- end)))
- (setf track-changes--before-end new-bend)
- (cl-callf concat track-changes--before-string
- (buffer-substring-no-properties old-bend new-bend))))))))
+ (point-max)))
+ (when (< beg track-changes--before-beg)
+ (if (and track-changes--disjoint-trackers
+ (funcall signal-if-disjoint end track-changes--before-beg))
+ (funcall reset)
+ (let* ((old-bbeg track-changes--before-beg)
+ ;; To avoid O(N²) behavior when faced with many small
+ ;; changes, we copy more than needed.
+ (new-bbeg
+ (min beg (max (point-min)
+ (- old-bbeg
+ (length track-changes--before-string))))))
+ (setf track-changes--before-beg new-bbeg)
+ (cl-callf (lambda (old new) (concat new old))
+ track-changes--before-string
+ (buffer-substring-no-properties new-bbeg old-bbeg)))))
+
+ (when (< track-changes--before-end end)
+ (if (and track-changes--disjoint-trackers
+ (funcall signal-if-disjoint track-changes--before-end beg))
+ (funcall reset)
+ (let* ((old-bend track-changes--before-end)
+ ;; To avoid O(N²) behavior when faced with many small
+ ;; changes, we copy more than needed.
+ (new-bend
+ (max end (min (point-max)
+ (+ old-bend
+ (length track-changes--before-string))))))
+ (setf track-changes--before-end new-bend)
+ (cl-callf concat track-changes--before-string
+ (buffer-substring-no-properties old-bend new-bend)))))))))
(defun track-changes--after (beg end len)
(cl-assert track-changes--state)