mirror of
https://github.com/neovim/neovim.git
synced 2026-08-27 09:31:47 +00:00
vim-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().
3df8f6e353
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -198,6 +198,7 @@ EXTERN const char e_failed_to_find_all_diff_anchors[] INIT( = N_("E1550: Failed
|
|||||||
EXTERN const char e_diff_anchors_with_hidden_windows[] INIT( = N_("E1562: Diff anchors cannot be used with hidden diff windows"));
|
EXTERN const char e_diff_anchors_with_hidden_windows[] INIT( = N_("E1562: Diff anchors cannot be used with hidden diff windows"));
|
||||||
|
|
||||||
EXTERN const char e_trustfile[] INIT(= N_("E5570: Cannot update trust file: %s"));
|
EXTERN const char e_trustfile[] INIT(= N_("E5570: Cannot update trust file: %s"));
|
||||||
|
EXTERN const char e_cannot_read_from_str_2[] INIT(= N_("E282: Cannot read from \"%s\""));
|
||||||
|
|
||||||
EXTERN const char e_unknown_option2[] INIT(= N_("E355: Unknown option: %s"));
|
EXTERN const char e_unknown_option2[] INIT(= N_("E355: Unknown option: %s"));
|
||||||
|
|
||||||
|
|||||||
@@ -2143,7 +2143,7 @@ static void source_startup_scripts(const mparm_T *const parmp)
|
|||||||
// Do nothing.
|
// Do nothing.
|
||||||
} else {
|
} else {
|
||||||
if (do_source(parmp->use_vimrc, false, DOSO_NONE, NULL) != OK) {
|
if (do_source(parmp->use_vimrc, false, DOSO_NONE, NULL) != OK) {
|
||||||
semsg(_("E282: Cannot read from \"%s\""), parmp->use_vimrc);
|
semsg(_(e_cannot_read_from_str_2), parmp->use_vimrc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!silent_mode) {
|
} else if (!silent_mode) {
|
||||||
|
|||||||
@@ -789,15 +789,20 @@ char *get_cmd_output(char *cmd, char *infile, int flags, size_t *ret_len)
|
|||||||
// read the names from the file into memory
|
// read the names from the file into memory
|
||||||
FILE *fd = os_fopen(tempname, READBIN);
|
FILE *fd = os_fopen(tempname, READBIN);
|
||||||
|
|
||||||
if (fd == NULL) {
|
// Not being able to seek means we can't read the file.
|
||||||
semsg(_(e_notopen), tempname);
|
long len_l;
|
||||||
|
if (fd == NULL
|
||||||
|
|| fseek(fd, 0L, SEEK_END) == -1
|
||||||
|
|| (len_l = ftell(fd)) == -1 // get size of temp file
|
||||||
|
|| fseek(fd, 0L, SEEK_SET) == -1) { // back to the start
|
||||||
|
semsg(_(e_cannot_read_from_str_2), tempname);
|
||||||
|
if (fd != NULL) {
|
||||||
|
fclose(fd);
|
||||||
|
}
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
fseek(fd, 0, SEEK_END);
|
size_t len = (size_t)len_l;
|
||||||
size_t len = (size_t)ftell(fd); // get size of temp file
|
|
||||||
fseek(fd, 0, SEEK_SET);
|
|
||||||
|
|
||||||
buffer = xmalloc(len + 1);
|
buffer = xmalloc(len + 1);
|
||||||
size_t i = fread(buffer, 1, len, fd);
|
size_t i = fread(buffer, 1, len, fd);
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
|
|||||||
Reference in New Issue
Block a user