Skip to content

Commit

Permalink
fix: prevent null issues when strings are unequal
Browse files Browse the repository at this point in the history
In the case where s2 is larger than s1, this errors because the index is
out of range.
  • Loading branch information
elken committed Mar 9, 2024
1 parent dd24c54 commit 5b5b488
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions apheleia-rcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ text of S1 surrounding P1."
(i1 (length s1))
(i2 (length s2)))
(while (> i1 p1)
(let ((ins (1+ (gethash (cons i1 (1- i2)) table)))
(del (1+ (gethash (cons (1- i1) i2) table)))
(sub (gethash (cons (1- i1) (1- i2)) table)))
(unless (= (aref s1 (1- i1)) (aref s2 (1- i2)))
(let ((ins (1+ (or (gethash (cons i1 (1- i2)) table) 1)))
(del (1+ (or (gethash (cons (1- i1) i2) table) 1)))
(sub (or (gethash (cons (1- i1) (1- i2)) table) 1)))
(unless (and (> 0 i2)
(= (aref s1 (1- i1)) (aref s2 (1- i2))))
(cl-incf sub))
(let ((cost (min ins del sub)))
(cond
Expand Down

0 comments on commit 5b5b488

Please sign in to comment.