Patch 8.2.4772

7 views
Skip to first unread message

Bram Moolenaar

unread,
Apr 17, 2022, 9:02:24 AM4/17/22
to vim...@googlegroups.com

Patch 8.2.4772
Problem: Old Coverity warning for not checking ftell() return value.
Solution: Check return value of fseek() and ftell().
Files: src/misc1.c


*** ../vim-8.2.4771/src/misc1.c 2022-04-15 23:29:19.410841325 +0100
--- src/misc1.c 2022-04-17 13:34:56.048904274 +0100
***************
*** 2337,2352 ****
fd = mch_fopen((char *)tempname, READBIN);
# endif

! if (fd == NULL)
{
! semsg(_(e_cant_open_file_str), tempname);
goto done;
}

- fseek(fd, 0L, SEEK_END);
- len = ftell(fd); // get size of temp file
- fseek(fd, 0L, SEEK_SET);
-
buffer = alloc(len + 1);
if (buffer != NULL)
i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd);
--- 2337,2354 ----
fd = mch_fopen((char *)tempname, READBIN);
# endif

! // 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_cannot_read_from_str), tempname);
! if (fd != NULL)
! fclose(fd);
goto done;
}

buffer = alloc(len + 1);
if (buffer != NULL)
i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd);
*** ../vim-8.2.4771/src/version.c 2022-04-17 13:17:36.620862242 +0100
--- src/version.c 2022-04-17 14:01:02.381636283 +0100
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 4772,
/**/

--
The goal of science is to build better mousetraps.
The goal of nature is to build better mice.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages