diff options
| author | Ellis Kenyo <me@elken.dev> | 2024-03-09 13:11:45 +0000 |
|---|---|---|
| committer | Ellis Kenyo <me@elken.dev> | 2024-03-09 13:18:15 +0000 |
| commit | 8c970d9b91987bac8d733fd12257348ac665b95e (patch) | |
| tree | 4012373a24fb0450786238b5a34b65584426ae56 | |
| parent | dd24c54897a19c2d7e0d90409bb23238fcac79f2 (diff) | |
fix: prevent null issues when strings are unequal
In the case where s2 is larger than s1, this errors because the index is
out of range.
---
no changelog update needed
| -rw-r--r-- | apheleia-rcs.el | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/apheleia-rcs.el b/apheleia-rcs.el index 2e10c12..bb900b4 100644 --- a/apheleia-rcs.el +++ b/apheleia-rcs.el @@ -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 |
