levenshtein.diff

application/octet-stream

Filename: levenshtein.diff
Type: application/octet-stream
Part: 0
Message: bug: fuzzystrmatch levenshtein is wrong

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: context
File+
contrib/fuzzystrmatch/fuzzystrmatch.c 5 6
index d42515f..090b970 100644
*** a/contrib/fuzzystrmatch/fuzzystrmatch.c
--- b/contrib/fuzzystrmatch/fuzzystrmatch.c
*************** levenshtein_internal(const char *s, cons
*** 207,219 ****
        n = strlen(t);

        /*
!        * If either m or n is 0, the answer is the other value. This makes sense
!        * since it would take that many insertions to build a matching string
         */
        if (!m)
!               return n;
        if (!n)
!               return m;

        /*
         * For security concerns, restrict excessive CPU+RAM usage. (This
--- 207,218 ----
        n = strlen(t);

        /*
!        * if either input is empty, the operation is all inserions or all deletions
         */
        if (!m)
!               return n * ins_c;
        if (!n)
!               return m * del_c;

        /*
         * For security concerns, restrict excessive CPU+RAM usage. (This
*************** levenshtein_internal(const char *s, cons
*** 241,247 ****

        /* Initialize the "previous" row to 0..cols */
        for (i = 0; i < m; i++)
!               prev[i] = i;

        /* Loop through rows of the notional array */
        for (y = t, j = 1; j < n; y++, j++)
--- 240,246 ----

        /* Initialize the "previous" row to 0..cols */
        for (i = 0; i < m; i++)
!               prev[i] = i * del_c;

        /* Loop through rows of the notional array */
        for (y = t, j = 1; j < n; y++, j++)
*************** levenshtein_internal(const char *s, cons
*** 252,258 ****
                 * First cell must increment sequentially, as we're on the j'th row of
                 * the (m+1)x(n+1) array.
                 */
!               curr[0] = j;

                for (x = s, i = 1; i < m; x++, i++)
                {
--- 251,257 ----
                 * First cell must increment sequentially, as we're on the j'th row of
                 * the (m+1)x(n+1) array.
                 */
!               curr[0] = j * ins_c;

                for (x = s, i = 1; i < m; x++, i++)
                {
*************** levenshtein_internal(const char *s, cons
*** 280,285 ****
--- 279,285 ----
         * Because the final value was swapped from the previous row to the
         * current row, that's where we'll find it.
         */
+
        return prev[m - 1];
  }