Skip to content

Commit

Permalink
HPCC-31453 Fix coverity warning in unicode edit distance
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
  • Loading branch information
ghalliday committed Mar 18, 2024
1 parent 43962f5 commit 6ac6ca6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions plugins/unicodelib/unicodelib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,13 @@ unsigned unicodeEditDistanceV3(UnicodeString & left, UnicodeString & right, unsi
leftLen = leftCEs.length();
rightLen = rightCEs.length();

// Check lengths again in case some pathological characters cause codepoints to be skipped/ignored
if (leftLen == 0)
return rightLen;

if (rightLen == 0)
return leftLen;

/*
This function applies two optimizations over the function above.
a) Adding a charcter (next row) can at most decrease the edit distance by 1, so short circuit when
Expand Down

0 comments on commit 6ac6ca6

Please sign in to comment.