diff options
| author | Philip Kaludercic | 2021-09-23 18:12:41 +0200 |
|---|---|---|
| committer | Mattias Engdegård | 2021-09-23 19:10:38 +0200 |
| commit | c44190ca5b9873fceae8aee7034ce8e89c42d4dd (patch) | |
| tree | 43a7d5ec8023ef2c7476ced38886ad78df92cf24 | |
| parent | 13d930deddd2e0529a0fb0f2fb93dd621d6d35be (diff) | |
| download | emacs-c44190ca5b9873fceae8aee7034ce8e89c42d4dd.tar.gz emacs-c44190ca5b9873fceae8aee7034ce8e89c42d4dd.zip | |
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.
| -rw-r--r-- | src/fns.c | 2 | ||||
| -rw-r--r-- | test/src/fns-tests.el | 10 |
2 files changed, 10 insertions, 2 deletions
| @@ -322,7 +322,7 @@ Letter-case is significant, but text properties are ignored. */) | |||
| 322 | 322 | ||
| 323 | USE_SAFE_ALLOCA; | 323 | USE_SAFE_ALLOCA; |
| 324 | ptrdiff_t *column = SAFE_ALLOCA ((len1 + 1) * sizeof (ptrdiff_t)); | 324 | ptrdiff_t *column = SAFE_ALLOCA ((len1 + 1) * sizeof (ptrdiff_t)); |
| 325 | for (y = 1; y <= len1; y++) | 325 | for (y = 0; y <= len1; y++) |
| 326 | column[y] = y; | 326 | column[y] = y; |
| 327 | 327 | ||
| 328 | if (use_byte_compare) | 328 | if (use_byte_compare) |
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index 9f6593a177c..bd5a4358e65 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el | |||
| @@ -786,7 +786,15 @@ | |||
| 786 | ;; string containing hanzi character, compare by character | 786 | ;; string containing hanzi character, compare by character |
| 787 | (should (equal 2 (string-distance "ab" "ab我她"))) | 787 | (should (equal 2 (string-distance "ab" "ab我她"))) |
| 788 | (should (equal 1 (string-distance "ab" "a我b"))) | 788 | (should (equal 1 (string-distance "ab" "a我b"))) |
| 789 | (should (equal 1 (string-distance "我" "她")))) | 789 | (should (equal 1 (string-distance "我" "她"))) |
| 790 | |||
| 791 | ;; correct behaviour with empty strings | ||
| 792 | (should (equal 0 (string-distance "" ""))) | ||
| 793 | (should (equal 0 (string-distance "" "" t))) | ||
| 794 | (should (equal 1 (string-distance "x" ""))) | ||
| 795 | (should (equal 1 (string-distance "x" "" t))) | ||
| 796 | (should (equal 1 (string-distance "" "x"))) | ||
| 797 | (should (equal 1 (string-distance "" "x" t)))) | ||
| 790 | 798 | ||
| 791 | (ert-deftest test-bignum-eql () | 799 | (ert-deftest test-bignum-eql () |
| 792 | "Test that `eql' works for bignums." | 800 | "Test that `eql' works for bignums." |