aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/ex_docmd.c28
-rw-r--r--src/nvim/if_cscope.c7
-rw-r--r--src/nvim/normal.c1
-rw-r--r--src/nvim/os_unix.c29
4 files changed, 37 insertions, 28 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index f6527db69b..9b48398d96 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -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;
diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c
index 843cbcf6f9..09f4ecf519 100644
--- a/src/nvim/if_cscope.c
+++ b/src/nvim/if_cscope.c
@@ -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);
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index f140922082..e147280723 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -834,6 +834,7 @@ getcount:
ca.cmdchar = Ctrl_BSL;
ca.nchar = c;
idx = find_command(ca.cmdchar);
+ assert(idx >= 0);
}
}
}
diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c
index f7b47f9569..d674db951f 100644
--- a/src/nvim/os_unix.c
+++ b/src/nvim/os_unix.c
@@ -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".