mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
vim-patch:9.1.1628: fuzzy.c has a few issues
Problem: fuzzy.c has a few issues
Solution: Use Vims memory management, update style
(glepnir)
Problem:
- Missing cleanup of lmatchpos lists causing memory leaks
- Missing error handling for list operations
- Use of malloc() instead of Vim's alloc() functions
- Inconsistent C-style comments
- Missing null pointer checks for memory allocation
- Incorrect use of vim_free() for list objects
Solution:
- Add proper cleanup of lmatchpos in done section using list_free()
- Set lmatchpos to NULL after successful transfer to avoid confusion
- Add error handling for list_append_tv() failures
- Replace malloc() with alloc() and add null pointer checks
- Convert C-style comments to C++ style for consistency
- Fix vim_free() calls to use list_free() for list objects
closes: vim/vim#17984
17a6d696bd
Co-authored-by: glepnir <glephunter@gmail.com>
This commit is contained in:
@@ -50,7 +50,7 @@
|
|||||||
typedef double score_t;
|
typedef double score_t;
|
||||||
|
|
||||||
#define SCORE_MAX INFINITY
|
#define SCORE_MAX INFINITY
|
||||||
#define SCORE_MIN -INFINITY
|
#define SCORE_MIN (-INFINITY)
|
||||||
#define SCORE_SCALE 1000
|
#define SCORE_SCALE 1000
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -253,8 +253,9 @@ static void fuzzy_match_in_list(list_T *const l, char *const str, const bool mat
|
|||||||
items[match_count].itemstr = itemstr_allocate ? xstrdup(itemstr) : itemstr;
|
items[match_count].itemstr = itemstr_allocate ? xstrdup(itemstr) : itemstr;
|
||||||
items[match_count].itemstr_allocated = itemstr_allocate;
|
items[match_count].itemstr_allocated = itemstr_allocate;
|
||||||
|
|
||||||
// Copy the list of matching positions in itemstr to a list.
|
// Copy the list of matching positions in itemstr to a list, if
|
||||||
{
|
// "retmatchpos" is set.
|
||||||
|
if (retmatchpos) {
|
||||||
items[match_count].lmatchpos = tv_list_alloc(kListLenMayKnow);
|
items[match_count].lmatchpos = tv_list_alloc(kListLenMayKnow);
|
||||||
int j = 0;
|
int j = 0;
|
||||||
const char *p = str;
|
const char *p = str;
|
||||||
@@ -305,6 +306,7 @@ static void fuzzy_match_in_list(list_T *const l, char *const str, const bool mat
|
|||||||
for (int i = 0; i < match_count; i++) {
|
for (int i = 0; i < match_count; i++) {
|
||||||
assert(items[i].lmatchpos != NULL);
|
assert(items[i].lmatchpos != NULL);
|
||||||
tv_list_append_list(retlist, items[i].lmatchpos);
|
tv_list_append_list(retlist, items[i].lmatchpos);
|
||||||
|
items[i].lmatchpos = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy the matching scores
|
// copy the matching scores
|
||||||
@@ -321,6 +323,7 @@ static void fuzzy_match_in_list(list_T *const l, char *const str, const bool mat
|
|||||||
if (items[i].itemstr_allocated) {
|
if (items[i].itemstr_allocated) {
|
||||||
xfree(items[i].itemstr);
|
xfree(items[i].itemstr);
|
||||||
}
|
}
|
||||||
|
assert(items[i].lmatchpos == NULL);
|
||||||
}
|
}
|
||||||
xfree(items);
|
xfree(items);
|
||||||
}
|
}
|
||||||
@@ -901,9 +904,8 @@ static score_t match_positions(const char *const needle, const char *const hayst
|
|||||||
// If this score was determined using
|
// If this score was determined using
|
||||||
// SCORE_MATCH_CONSECUTIVE, the
|
// SCORE_MATCH_CONSECUTIVE, the
|
||||||
// previous character MUST be a match
|
// previous character MUST be a match
|
||||||
match_required =
|
match_required = i && j
|
||||||
i && j
|
&& M[i][j] == D[i - 1][j - 1] + SCORE_MATCH_CONSECUTIVE;
|
||||||
&& M[i][j] == D[i - 1][j - 1] + SCORE_MATCH_CONSECUTIVE;
|
|
||||||
positions[i] = (uint32_t)(j--);
|
positions[i] = (uint32_t)(j--);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user