vim-patch:9.2.0091: missing out-of-memory checks in quickfix.c

Problem:  missing out-of-memory checks in quickfix.c
Solution: Improve error handline, refactor qf_push_dir() slightly
          (John Marriott).

closes: vim/vim#19528

0155401538

Co-authored-by: John Marriott <basilisk@internode.on.net>
This commit is contained in:
zeertzjq
2026-03-04 09:05:37 +08:00
parent 813457d5a6
commit 0cfeedb088

View File

@@ -2365,9 +2365,10 @@ static char *qf_push_dir(char *dirbuf, struct dir_stack_T **stackptr, bool is_fi
{
struct dir_stack_T *ds_ptr;
// allocate new stack element and hook it in
// allocate new stack element
struct dir_stack_T *ds_new = xmalloc(sizeof(struct dir_stack_T));
// push the new element onto the stack
ds_new->next = *stackptr;
*stackptr = ds_new;
@@ -2383,9 +2384,10 @@ static char *qf_push_dir(char *dirbuf, struct dir_stack_T **stackptr, bool is_fi
ds_new = (*stackptr)->next;
(*stackptr)->dirname = NULL;
while (ds_new) {
xfree((*stackptr)->dirname);
(*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf, true);
if (os_isdir((*stackptr)->dirname)) {
char *dirname = concat_fnames(ds_new->dirname, dirbuf, true);
if (os_isdir(dirname)) {
xfree((*stackptr)->dirname);
(*stackptr)->dirname = dirname;
break;
}
@@ -2410,9 +2412,12 @@ static char *qf_push_dir(char *dirbuf, struct dir_stack_T **stackptr, bool is_fi
if ((*stackptr)->dirname != NULL) {
return (*stackptr)->dirname;
}
// pop the new element from the stack and free it
ds_ptr = *stackptr;
*stackptr = (*stackptr)->next;
xfree(ds_ptr);
return NULL;
}