0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

patch 8.2.4772: old Coverity warning for not checking ftell() return value

Problem:    Old Coverity warning for not checking ftell() return value.
Solution:   Check return value of fseek() and ftell().
This commit is contained in:
Bram Moolenaar
2022-04-17 14:01:51 +01:00
parent 066e0d9869
commit 3df8f6e353
2 changed files with 10 additions and 6 deletions

View File

@@ -2337,16 +2337,18 @@ get_cmd_output(
fd = mch_fopen((char *)tempname, READBIN); fd = mch_fopen((char *)tempname, READBIN);
# endif # endif
if (fd == NULL) // Not being able to seek means we can't read the file.
if (fd == NULL
|| fseek(fd, 0L, SEEK_END) == -1
|| (len = ftell(fd)) == -1 // get size of temp file
|| fseek(fd, 0L, SEEK_SET) == -1) // back to the start
{ {
semsg(_(e_cant_open_file_str), tempname); semsg(_(e_cannot_read_from_str), tempname);
if (fd != NULL)
fclose(fd);
goto done; goto done;
} }
fseek(fd, 0L, SEEK_END);
len = ftell(fd); // get size of temp file
fseek(fd, 0L, SEEK_SET);
buffer = alloc(len + 1); buffer = alloc(len + 1);
if (buffer != NULL) if (buffer != NULL)
i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd); i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd);

View File

@@ -746,6 +746,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 */
/**/
4772,
/**/ /**/
4771, 4771,
/**/ /**/