Skip to content

Commit

Permalink
Merge neovim#1896 'Fix coverity issues. (3)'
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmk committed Feb 2, 2015
2 parents 4d70aae + bb674e0 commit 6360be9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 28 deletions.
2 changes: 2 additions & 0 deletions config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 8 additions & 20 deletions src/nvim/ex_docmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/nvim/if_cscope.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/nvim/normal.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ normal_cmd (
ca.cmdchar = Ctrl_BSL;
ca.nchar = c;
idx = find_command(ca.cmdchar);
assert(idx >= 0);
}
}
}
Expand Down
29 changes: 23 additions & 6 deletions src/nvim/os_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* changed beyond recognition.
*/

#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
Expand Down Expand Up @@ -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);
Expand All @@ -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 */
Expand Down Expand Up @@ -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".
Expand Down

0 comments on commit 6360be9

Please sign in to comment.