1
0
forked from aniani/vim

patch 8.0.0526: Coverity complains about possible negative value

Problem:    Coverity complains about possible negative value.
Solution:   Check return value of ftell() not to be negative.
This commit is contained in:
Bram Moolenaar
2017-03-30 21:18:45 +02:00
parent a33ddbbd04
commit 85325f839a
2 changed files with 10 additions and 2 deletions

View File

@@ -6006,6 +6006,7 @@ mch_expand_wildcards(
{ {
int i; int i;
size_t len; size_t len;
long llen;
char_u *p; char_u *p;
int dir; int dir;
@@ -6292,9 +6293,13 @@ mch_expand_wildcards(
goto notfound; goto notfound;
} }
fseek(fd, 0L, SEEK_END); fseek(fd, 0L, SEEK_END);
len = ftell(fd); /* get size of temp file */ llen = ftell(fd); /* get size of temp file */
fseek(fd, 0L, SEEK_SET); fseek(fd, 0L, SEEK_SET);
buffer = alloc(len + 1); if (llen < 0)
/* just in case ftell() would fail */
buffer = NULL;
else
buffer = alloc(llen + 1);
if (buffer == NULL) if (buffer == NULL)
{ {
/* out of memory */ /* out of memory */
@@ -6303,6 +6308,7 @@ mch_expand_wildcards(
fclose(fd); fclose(fd);
return FAIL; return FAIL;
} }
len = llen;
i = fread((char *)buffer, 1, len, fd); i = fread((char *)buffer, 1, len, fd);
fclose(fd); fclose(fd);
mch_remove(tempname); mch_remove(tempname);

View File

@@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
526,
/**/ /**/
525, 525,
/**/ /**/