ptr = concat_fnames(directory, fname, TRUE);
else
ptr = vim_strsave(fname);
+ if (ptr == NULL)
+ return 0;
}
// Use concatenated directory name and file name
bufname = ptr;
struct dir_stack_T *ds_new;
struct dir_stack_T *ds_ptr;
- // allocate new stack element and hook it in
+ // allocate new stack element
ds_new = ALLOC_ONE_ID(struct dir_stack_T, aid_qf_dirstack);
if (ds_new == NULL)
return NULL;
+ // push the new element onto the stack
ds_new->next = *stackptr;
*stackptr = ds_new;
(*stackptr)->dirname = NULL;
while (ds_new)
{
- vim_free((*stackptr)->dirname);
- (*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf,
- TRUE);
- if (mch_isdir((*stackptr)->dirname) == TRUE)
+ char_u *dirname;
+
+ dirname = concat_fnames(ds_new->dirname, dirbuf, TRUE);
+ if (dirname == NULL)
+ {
+ // pop the new element from the stack and free it
+ ds_ptr = *stackptr;
+ *stackptr = (*stackptr)->next;
+ vim_free(ds_ptr);
+
+ return NULL;
+ }
+ if (mch_isdir(dirname) == TRUE)
+ {
+ vim_free((*stackptr)->dirname);
+ (*stackptr)->dirname = dirname;
break;
+ }
ds_new = ds_new->next;
}
if ((*stackptr)->dirname != NULL)
return (*stackptr)->dirname;
- else
- {
- ds_ptr = *stackptr;
- *stackptr = (*stackptr)->next;
- vim_free(ds_ptr);
- return NULL;
- }
+
+ // pop the new element from the stack and free it
+ ds_ptr = *stackptr;
+ *stackptr = (*stackptr)->next;
+ vim_free(ds_ptr);
+
+ return NULL;
}
/*