aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2015-09-20 10:11:24 -0400
committerJustin M. Keyes <justinkz@gmail.com>2015-09-23 00:06:27 -0400
commit6eb78dcaaa6af509e7dce221e88047b5869ced20 (patch)
tree0cd8c8f2586101c8c3818632ce47a38c68912fcd
parent3c32ae2ff3f8e8c0879d7adc7b0f4d4023424a25 (diff)
downloadrneovim-6eb78dcaaa6af509e7dce221e88047b5869ced20.tar.gz
rneovim-6eb78dcaaa6af509e7dce221e88047b5869ced20.tar.bz2
rneovim-6eb78dcaaa6af509e7dce221e88047b5869ced20.zip
nv_ident: sprintf => snprintf
Also fix some other clint errors.
-rw-r--r--src/nvim/normal.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 8ce2065336..467b74f9e6 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -4253,10 +4253,11 @@ static void nv_ident(cmdarg_T *cap)
/* Allocate buffer to put the command in. Inserting backslashes can
* double the length of the word. p_kp / curbuf->b_p_kp could be added
* and some numbers. */
- char_u *kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); //'keywordprg'
- assert(*kp != NUL); //option.c::do_set() should default to ":help" if empty.
- bool kp_ex = (*kp == ':'); //'keywordprg' is an ex command
- char *buf = xmalloc(n * 2 + 30 + STRLEN(kp));
+ char_u *kp = *curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp; // 'keywordprg'
+ assert(*kp != NUL); // option.c:do_set() should default to ":help" if empty.
+ bool kp_ex = (*kp == ':'); // 'keywordprg' is an ex command
+ size_t buf_size = n * 2 + 30 + STRLEN(kp);
+ char *buf = xmalloc(buf_size);
buf[0] = NUL;
switch (cmdchar) {
@@ -4279,7 +4280,7 @@ static void nv_ident(cmdarg_T *cap)
case 'K':
if (kp_ex) {
if (cap->count0 != 0) { // Send the count to the ex command.
- sprintf(buf, "%" PRId64, (int64_t)(cap->count0));
+ snprintf(buf, buf_size, "%" PRId64, (int64_t)(cap->count0));
}
STRCAT(buf, kp);
STRCAT(buf, " ");
@@ -4300,17 +4301,20 @@ static void nv_ident(cmdarg_T *cap)
* really what we want? */
bool isman = (STRCMP(kp, "man") == 0);
bool isman_s = (STRCMP(kp, "man -s") == 0);
- if (cap->count0 != 0 && !(isman || isman_s))
- sprintf(buf, ".,.+%" PRId64, (int64_t)(cap->count0 - 1));
+ if (cap->count0 != 0 && !(isman || isman_s)) {
+ snprintf(buf, buf_size, ".,.+%" PRId64, (int64_t)(cap->count0 - 1));
+ }
STRCAT(buf, "! ");
- if (cap->count0 == 0 && isman_s)
+ if (cap->count0 == 0 && isman_s) {
STRCAT(buf, "man");
- else
+ } else {
STRCAT(buf, kp);
+ }
STRCAT(buf, " ");
if (cap->count0 != 0 && (isman || isman_s)) {
- sprintf(buf + STRLEN(buf), "%" PRId64, (int64_t)cap->count0);
+ snprintf(buf + STRLEN(buf), buf_size - STRLEN(buf), "%" PRId64,
+ (int64_t)cap->count0);
STRCAT(buf, " ");
}
}
@@ -4332,7 +4336,7 @@ static void nv_ident(cmdarg_T *cap)
if (g_cmd)
STRCPY(buf, "tj ");
else
- sprintf(buf, "%" PRId64 "ta ", (int64_t)cap->count0);
+ snprintf(buf, buf_size, "%" PRId64 "ta ", (int64_t)cap->count0);
}
}
@@ -4391,8 +4395,9 @@ static void nv_ident(cmdarg_T *cap)
init_history();
add_to_history(HIST_SEARCH, (char_u *)buf, true, NUL);
(void)normal_search(cap, cmdchar == '*' ? '/' : '?', (char_u *)buf, 0);
- } else
+ } else {
do_cmdline_cmd(buf);
+ }
xfree(buf);
}