summaryrefslogtreecommitdiffstats
path: root/src/misc1.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-04-17 14:01:51 +0100
committerBram Moolenaar <Bram@vim.org>2022-04-17 14:01:51 +0100
commit3df8f6e353eeaf24bb5fe3769ed07c03791bb58e (patch)
tree6711002af326115a8deedf31a36ec153b9430eb5 /src/misc1.c
parent066e0d9869a16d89b1b2336b4150f476c5337283 (diff)
patch 8.2.4772: old Coverity warning for not checking ftell() return valuev8.2.4772
Problem: Old Coverity warning for not checking ftell() return value. Solution: Check return value of fseek() and ftell().
Diffstat (limited to 'src/misc1.c')
-rw-r--r--src/misc1.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/misc1.c b/src/misc1.c
index 632d222b6c..3b8464ec13 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -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);