Fix string-distance for two empty strings

* fns.c (Fstring_distance): Avoid using uninitialized memory.
* test/src/fns-tests.el (test-string-distance): Add test cases.
This commit is contained in:
Philip Kaludercic 2021-09-23 18:12:41 +02:00 committed by Mattias Engdegård
parent 13d930dedd
commit c44190ca5b
2 changed files with 10 additions and 2 deletions

View file

@ -322,7 +322,7 @@ Letter-case is significant, but text properties are ignored. */)
USE_SAFE_ALLOCA;
ptrdiff_t *column = SAFE_ALLOCA ((len1 + 1) * sizeof (ptrdiff_t));
for (y = 1; y <= len1; y++)
for (y = 0; y <= len1; y++)
column[y] = y;
if (use_byte_compare)

View file

@ -786,7 +786,15 @@
;; string containing hanzi character, compare by character
(should (equal 2 (string-distance "ab" "ab我她")))
(should (equal 1 (string-distance "ab" "a我b")))
(should (equal 1 (string-distance "" ""))))
(should (equal 1 (string-distance "" "")))
;; correct behaviour with empty strings
(should (equal 0 (string-distance "" "")))
(should (equal 0 (string-distance "" "" t)))
(should (equal 1 (string-distance "x" "")))
(should (equal 1 (string-distance "x" "" t)))
(should (equal 1 (string-distance "" "x")))
(should (equal 1 (string-distance "" "x" t))))
(ert-deftest test-bignum-eql ()
"Test that `eql' works for bignums."