abo-abo / avy

Jump to things in Emacs tree-style
1.7k stars 108 forks source link

add-text-properties can be called on empty string #351

Closed djr7C4 closed 1 year ago

djr7C4 commented 2 years ago

I am not sure exactly what the conditions are that cause this bug to actually occur, but sometimes when avy-goto-char is called on some files it is possible for an error to occur. The culprits appear to be these lines in avy--overlay:

(when os-line-prefix
  (add-text-properties 0 1 `(line-prefix ,os-line-prefix) str))
(when os-wrap-prefix
  (add-text-properties 0 1 `(wrap-prefix ,os-wrap-prefix) str)))

Sometimes when avy--overlay is called, str can be the empty string which causes the following error when add-text-properties

progn: Args out of range: 0, 1

Fortunately, it is easy to fix this by making sure that str is not empty before these two calls to add-text-properties. I will submit a pull request shortly. I have also attached a minimal example of when this error occurs. Simply go the bottom of the buffer and then press M-x avy-goto-char m and the error should occur. break-avy.txt