]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4772: old Coverity warning for not checking ftell() return value v8.2.4772
authorBram Moolenaar <Bram@vim.org>
Sun, 17 Apr 2022 13:01:51 +0000 (14:01 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 17 Apr 2022 13:01:51 +0000 (14:01 +0100)
Problem:    Old Coverity warning for not checking ftell() return value.
Solution:   Check return value of fseek() and ftell().

src/misc1.c
src/version.c

index 632d222b6c87f4c9bd1b924e386234576c9f6a0d..3b8464ec13cbc901669dafd1fc564b15960df443 100644 (file)
@@ -2337,16 +2337,18 @@ get_cmd_output(
     fd = mch_fopen((char *)tempname, READBIN);
 # 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;
     }
 
-    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);
index c5ac7c5eee14c9c0c21c2650b8720be54d04a31f..fdc2508a6044514f9b84e6878c96dccde1eba989 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4772,
 /**/
     4771,
 /**/