Mercurial > vim
comparison src/misc1.c @ 28495:f285dd00704e v8.2.4772
patch 8.2.4772: old Coverity warning for not checking ftell() return value
Commit: https://github.com/vim/vim/commit/3df8f6e353eeaf24bb5fe3769ed07c03791bb58e
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 17 14:01:51 2022 +0100
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().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 17 Apr 2022 15:15:03 +0200 |
parents | 8bf3198ca147 |
children | 7c4a9e20c178 |
comparison
equal
deleted
inserted
replaced
28494:6a015080f040 | 28495:f285dd00704e |
---|---|
2335 fd = mch_fopen((char *)tempname, "r"); | 2335 fd = mch_fopen((char *)tempname, "r"); |
2336 # else | 2336 # else |
2337 fd = mch_fopen((char *)tempname, READBIN); | 2337 fd = mch_fopen((char *)tempname, READBIN); |
2338 # endif | 2338 # endif |
2339 | 2339 |
2340 if (fd == NULL) | 2340 // Not being able to seek means we can't read the file. |
2341 { | 2341 if (fd == NULL |
2342 semsg(_(e_cant_open_file_str), tempname); | 2342 || fseek(fd, 0L, SEEK_END) == -1 |
2343 || (len = ftell(fd)) == -1 // get size of temp file | |
2344 || fseek(fd, 0L, SEEK_SET) == -1) // back to the start | |
2345 { | |
2346 semsg(_(e_cannot_read_from_str), tempname); | |
2347 if (fd != NULL) | |
2348 fclose(fd); | |
2343 goto done; | 2349 goto done; |
2344 } | 2350 } |
2345 | |
2346 fseek(fd, 0L, SEEK_END); | |
2347 len = ftell(fd); // get size of temp file | |
2348 fseek(fd, 0L, SEEK_SET); | |
2349 | 2351 |
2350 buffer = alloc(len + 1); | 2352 buffer = alloc(len + 1); |
2351 if (buffer != NULL) | 2353 if (buffer != NULL) |
2352 i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd); | 2354 i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd); |
2353 fclose(fd); | 2355 fclose(fd); |