Fix problem with coverity/105568 fix.

The original fix 3db0a40d69
does not work for more than one loop iteration, because memory allocated
in the previous iteration could be reused in the current iteration.

Because expand_wildcards() never reads the variables *num_file
and *file before the first assignment to them, the initial
values for these variables can be anything. So instead of
calling expand_shellcmd() with *file = "" we set *file = NULL.
That should help coverity see, that not a array-typed value
is freed.

Helped-by: Eliseo Martínez <eliseomarmol@gmail.com>
This commit is contained in:
oni-link 2015-03-24 19:46:39 +01:00 committed by Justin M. Keyes
parent adb3ec2026
commit 8ee6f90bf8

View File

@ -10,7 +10,6 @@
* ex_getln.c: Functions for entering and editing an Ex command line.
*/
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <string.h>
@ -3629,6 +3628,7 @@ ExpandFromContext (
}
if (xp->xp_context == EXPAND_SHELLCMD) {
*file = NULL;
expand_shellcmd(pat, num_file, file, flags);
return OK;
}
@ -3876,10 +3876,8 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
STRLCPY(buf + l, pat, MAXPATHL - l);
/* Expand matches in one directory of $PATH. */
char_u **prev_file = *file;
ret = expand_wildcards(1, &buf, num_file, file, flags);
if (ret == OK) {
assert(*file != prev_file);
ga_grow(&ga, *num_file);
{
for (i = 0; i < *num_file; ++i) {