mirror of
https://github.com/neovim/neovim.git
synced 2026-07-12 12:29:44 +00:00
Merge #1896 'Fix coverity issues. (3)'
This commit is contained in:
@@ -7,6 +7,8 @@ check_type_size("int" SIZEOF_INT)
|
||||
check_type_size("long" SIZEOF_LONG)
|
||||
check_type_size("intmax_t" SIZEOF_INTMAX_T)
|
||||
check_type_size("off_t" SIZEOF_OFF_T)
|
||||
check_type_size("size_t" SIZEOF_SIZE_T)
|
||||
check_type_size("long long" SIZEOF_LONG_LONG)
|
||||
check_type_size("void *" SIZEOF_VOID_PTR)
|
||||
|
||||
check_symbol_exists(_NSGetEnviron crt_externs.h HAVE__NSGETENVIRON)
|
||||
|
||||
@@ -3219,27 +3219,15 @@ get_address (
|
||||
}
|
||||
|
||||
if (!skip) {
|
||||
/*
|
||||
* When search follows another address, start from
|
||||
* there.
|
||||
*/
|
||||
if (lnum != MAXLNUM)
|
||||
pos.lnum = lnum;
|
||||
else
|
||||
pos.lnum = curwin->w_cursor.lnum;
|
||||
|
||||
/*
|
||||
* Start the search just like for the above
|
||||
* do_search().
|
||||
*/
|
||||
if (*cmd != '?')
|
||||
pos.col = MAXCOL;
|
||||
else
|
||||
pos.col = 0;
|
||||
// When search follows another address, start from there.
|
||||
pos.lnum = (lnum != MAXLNUM) ? lnum : curwin->w_cursor.lnum;
|
||||
// Start the search just like for the above do_search().
|
||||
pos.col = (*cmd != '?') ? MAXCOL : 0;
|
||||
pos.coladd = 0;
|
||||
if (searchit(curwin, curbuf, &pos,
|
||||
*cmd == '?' ? BACKWARD : FORWARD,
|
||||
(char_u *)"", 1L, SEARCH_MSG,
|
||||
i, (linenr_T)0, NULL) != FAIL)
|
||||
*cmd == '?' ? BACKWARD : FORWARD,
|
||||
(char_u *)"", 1L, SEARCH_MSG,
|
||||
i, (linenr_T)0, NULL) != FAIL)
|
||||
lnum = pos.lnum;
|
||||
else {
|
||||
cmd = NULL;
|
||||
|
||||
@@ -1646,7 +1646,6 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches)
|
||||
char *fname, *lno, *extra, *tbuf;
|
||||
int i, idx, num;
|
||||
char *globalcntx = "GLOBAL";
|
||||
char *cntxformat = " <<%s>>";
|
||||
char *context;
|
||||
char *cstag_msg = _("Cscope tag: %s");
|
||||
|
||||
@@ -1706,7 +1705,11 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches)
|
||||
context = cntxts[idx];
|
||||
else
|
||||
context = globalcntx;
|
||||
newsize = strlen(context) + strlen(cntxformat);
|
||||
|
||||
const char *cntxformat = " <<%s>>";
|
||||
// '%s' won't appear in result string, so:
|
||||
// newsize = len(cntxformat) - 2 + len(context) + 1 (for NUL).
|
||||
newsize = strlen(context) + strlen(cntxformat) - 1;
|
||||
|
||||
if (bufsize < newsize) {
|
||||
buf = xrealloc(buf, newsize);
|
||||
|
||||
@@ -834,6 +834,7 @@ getcount:
|
||||
ca.cmdchar = Ctrl_BSL;
|
||||
ca.nchar = c;
|
||||
idx = find_command(ca.cmdchar);
|
||||
assert(idx >= 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* changed beyond recognition.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
@@ -1158,14 +1159,30 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
|
||||
free(tempname);
|
||||
goto notfound;
|
||||
}
|
||||
fseek(fd, 0L, SEEK_END);
|
||||
len = ftell(fd); /* get size of temp file */
|
||||
int fseek_res = fseek(fd, 0L, SEEK_END);
|
||||
if (fseek_res < 0) {
|
||||
free(tempname);
|
||||
fclose(fd);
|
||||
return FAIL;
|
||||
}
|
||||
long long templen = ftell(fd); /* get size of temp file */
|
||||
if (templen < 0) {
|
||||
free(tempname);
|
||||
fclose(fd);
|
||||
return FAIL;
|
||||
}
|
||||
#if SIZEOF_LONG_LONG > SIZEOF_SIZE_T
|
||||
assert(templen <= (long long)SIZE_MAX);
|
||||
#endif
|
||||
len = (size_t)templen;
|
||||
fseek(fd, 0L, SEEK_SET);
|
||||
buffer = xmalloc(len + 1);
|
||||
i = fread((char *)buffer, 1, len, fd);
|
||||
// fread() doesn't terminate buffer with NUL;
|
||||
// appropiate termination (not always NUL) is done below.
|
||||
size_t readlen = fread((char *)buffer, 1, len, fd);
|
||||
fclose(fd);
|
||||
os_remove((char *)tempname);
|
||||
if (i != (int)len) {
|
||||
if (readlen != len) {
|
||||
/* unexpected read error */
|
||||
EMSG2(_(e_notread), tempname);
|
||||
free(tempname);
|
||||
@@ -1174,8 +1191,6 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
|
||||
}
|
||||
free(tempname);
|
||||
|
||||
|
||||
|
||||
/* file names are separated with Space */
|
||||
if (shell_style == STYLE_ECHO) {
|
||||
buffer[len] = '\n'; /* make sure the buffer ends in NL */
|
||||
@@ -1235,6 +1250,8 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
|
||||
if (len)
|
||||
++i; /* count last entry */
|
||||
}
|
||||
assert(buffer[len] == NUL || buffer[len] == '\n');
|
||||
|
||||
if (i == 0) {
|
||||
/*
|
||||
* Can happen when using /bin/sh and typing ":e $NO_SUCH_VAR^I".
|
||||
|
||||
Reference in New Issue
Block a user