fix(cli): possible divide-by-zero when calculating similarity

If given two empty strings (which doesn't happens anywhere in the
codebase atm, but just in case).
This commit is contained in:
Henrik Lissner 2022-06-19 12:13:12 +02:00
parent 979495cf33
commit 42d84e7e21
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -169,10 +169,10 @@ OPTIONS:
(s2 (downcase s2)) (s2 (downcase s2))
(s1len (length s1)) (s1len (length s1))
(s2len (length s2))) (s2len (length s2)))
(/ (if (or (zerop s1len) (if (or (zerop s1len)
(zerop s2len)) (zerop s2len))
0.0 0.0
(let ((i 0) (j 0) (score 0) jlast) (/ (let ((i 0) (j 0) (score 0) jlast)
(while (< i s1len) (while (< i s1len)
(unless jlast (setq jlast j)) (unless jlast (setq jlast j))
(if (and (< j s2len) (if (and (< j s2len)
@ -186,9 +186,9 @@ OPTIONS:
(setq j (or jlast j) (setq j (or jlast j)
jlast nil) jlast nil)
(cl-incf i)))) (cl-incf i))))
(* 2.0 score))) (* 2.0 score))
(+ (length s1) (+ (length s1)
(length s2))))) (length s2))))))
;;; Help: printers ;;; Help: printers
;; TODO Parameterize optional args with `cl-defun' ;; TODO Parameterize optional args with `cl-defun'