1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Ensure Soundex difference() function handles empty input sanely.

fuzzystrmatch's difference() function assumes that _soundex()
always initializes its output buffer fully.  This was not so for
the case of a string containing no alphabetic characters, resulting
in unstable output and Valgrind complaints.

Fix by using memset() to fill the whole buffer in the early-exit
case.  Also make some cosmetic improvements (I didn't care for the
random switches between "instr[0]" and "*instr" notation).

Report and diagnosis by Alexander Lakhin (bug #17935).
Back-patch to all supported branches.

Discussion: https://postgr.es/m/17935-b99316aa79c18513@postgresql.org
This commit is contained in:
Tom Lane
2023-05-16 10:53:42 -04:00
parent 27debd05dc
commit 1d369c9e90
3 changed files with 15 additions and 7 deletions

View File

@ -23,6 +23,12 @@ SELECT soundex('Anne'), soundex('Margaret'), difference('Anne', 'Margaret');
A500 | M626 | 0
(1 row)
SELECT soundex(''), difference('', '');
soundex | difference
---------+------------
| 4
(1 row)
SELECT levenshtein('GUMBO', 'GAMBOL');
levenshtein
-------------