aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2014-06-13 18:09:08 -0400
committerJustin M. Keyes <justinkz@gmail.com>2014-06-13 18:09:08 -0400
commit8bbeb4b480a72d0099a18c4d8200313600045231 (patch)
treecf153eceb121aef15e50631282e9171a24b74406 /src
parent5b3b3fd3ed4372866730ae857e8c09d6e5d1167d (diff)
parentd430f039d1255eaab55470b5613d83c24d030a64 (diff)
downloadrneovim-8bbeb4b480a72d0099a18c4d8200313600045231.tar.gz
rneovim-8bbeb4b480a72d0099a18c4d8200313600045231.tar.bz2
rneovim-8bbeb4b480a72d0099a18c4d8200313600045231.zip
Merge #743 'Replace vim_strncpy with strlcpy'
Diffstat (limited to 'src')
-rw-r--r--src/nvim/buffer.c23
-rw-r--r--src/nvim/eval.c2
-rw-r--r--src/nvim/ex_docmd.c7
-rw-r--r--src/nvim/ex_getln.c6
-rw-r--r--src/nvim/file_search.c4
-rw-r--r--src/nvim/fold.c2
-rw-r--r--src/nvim/getchar.c4
-rw-r--r--src/nvim/hardcopy.c11
-rw-r--r--src/nvim/if_cscope.c6
-rw-r--r--src/nvim/mark.c4
-rw-r--r--src/nvim/memline.c7
-rw-r--r--src/nvim/memory.c1
-rw-r--r--src/nvim/menu.c6
-rw-r--r--src/nvim/message.c3
-rw-r--r--src/nvim/misc1.c10
-rw-r--r--src/nvim/misc2.c2
-rw-r--r--src/nvim/ops.c2
-rw-r--r--src/nvim/option.c4
-rw-r--r--src/nvim/os/fs.c4
-rw-r--r--src/nvim/os/users.c2
-rw-r--r--src/nvim/os_unix.c6
-rw-r--r--src/nvim/path.c2
-rw-r--r--src/nvim/quickfix.c12
-rw-r--r--src/nvim/regexp.c2
-rw-r--r--src/nvim/screen.c6
-rw-r--r--src/nvim/spell.c71
-rw-r--r--src/nvim/syntax.c6
-rw-r--r--src/nvim/tag.c19
-rw-r--r--src/nvim/version.c7
-rw-r--r--src/nvim/vim.h2
30 files changed, 118 insertions, 125 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index ddd151f45a..db611823fc 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -2126,7 +2126,7 @@ void buflist_list(exarg_T *eap)
continue;
msg_putchar('\n');
if (buf_spname(buf) != NULL)
- vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1);
+ STRLCPY(NameBuff, buf_spname(buf), MAXPATHL);
else
home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE);
@@ -2473,7 +2473,7 @@ fileinfo (
*p++ = '"';
if (buf_spname(curbuf) != NULL)
- vim_strncpy(p, buf_spname(curbuf), IOSIZE - (p - buffer) - 1);
+ STRLCPY(p, buf_spname(curbuf), IOSIZE - (p - buffer));
else {
if (!fullname && curbuf->b_fname != NULL)
name = curbuf->b_fname;
@@ -2619,10 +2619,10 @@ void maketitle(void)
#define SPACE_FOR_DIR (IOSIZE - 20)
#define SPACE_FOR_ARGNR (IOSIZE - 10) /* at least room for " - VIM" */
if (curbuf->b_fname == NULL)
- vim_strncpy(buf, (char_u *)_("[No Name]"), SPACE_FOR_FNAME);
+ STRLCPY(buf, _("[No Name]"), SPACE_FOR_FNAME + 1);
else {
p = transstr(path_tail(curbuf->b_fname));
- vim_strncpy(buf, p, SPACE_FOR_FNAME);
+ STRLCPY(buf, p, SPACE_FOR_FNAME + 1);
free(p);
}
@@ -2654,8 +2654,7 @@ void maketitle(void)
p = path_tail_with_sep(buf + off);
if (p == buf + off)
/* must be a help buffer */
- vim_strncpy(buf + off, (char_u *)_("help"),
- (size_t)(SPACE_FOR_DIR - off - 1));
+ STRLCPY(buf + off, _("help"), SPACE_FOR_DIR - off);
else
*p = NUL;
@@ -2664,11 +2663,10 @@ void maketitle(void)
* file name) use (...). */
if (off < SPACE_FOR_DIR) {
p = transstr(buf + off);
- vim_strncpy(buf + off, p, (size_t)(SPACE_FOR_DIR - off));
+ STRLCPY(buf + off, p, SPACE_FOR_DIR - off + 1);
free(p);
} else {
- vim_strncpy(buf + off, (char_u *)"...",
- (size_t)(SPACE_FOR_ARGNR - off));
+ STRLCPY(buf + off, "...", SPACE_FOR_ARGNR - off + 1);
}
STRCAT(buf, ")");
}
@@ -3071,7 +3069,7 @@ build_stl_str_hl (
case STL_FILENAME:
fillable = FALSE; /* don't change ' ' to fillchar */
if (buf_spname(wp->w_buffer) != NULL)
- vim_strncpy(NameBuff, buf_spname(wp->w_buffer), MAXPATHL - 1);
+ STRLCPY(NameBuff, buf_spname(wp->w_buffer), MAXPATHL);
else {
t = (opt == STL_FULLPATH) ? wp->w_buffer->b_ffname
: wp->w_buffer->b_fname;
@@ -3513,10 +3511,9 @@ void get_rel_pos(win_T *wp, char_u *buf, int buflen)
above += diff_check_fill(wp, wp->w_topline) - wp->w_topfill;
below = wp->w_buffer->b_ml.ml_line_count - wp->w_botline + 1;
if (below <= 0)
- vim_strncpy(buf, (char_u *)(above == 0 ? _("All") : _("Bot")),
- (size_t)(buflen - 1));
+ STRLCPY(buf, (above == 0 ? _("All") : _("Bot")), buflen);
else if (above <= 0)
- vim_strncpy(buf, (char_u *)_("Top"), (size_t)(buflen - 1));
+ STRLCPY(buf, _("Top"), buflen);
else
vim_snprintf((char *)buf, (size_t)buflen, "%2d%%", above > 1000000L
? (int)(above / ((above + below) / 100L))
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index e6a16cc0bf..e4e90142cc 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -5875,7 +5875,7 @@ dictitem_T *dict_find(dict_T *d, char_u *key, int len)
tofree = akey = vim_strnsave(key, len);
} else {
/* Avoid a malloc/free by using buf[]. */
- vim_strncpy(buf, key, len);
+ STRLCPY(buf, key, len + 1);
akey = buf;
}
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 31243a12c4..e39eac993c 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -4095,9 +4095,8 @@ check_more (
char_u buff[DIALOG_MSG_SIZE];
if (n == 1)
- vim_strncpy(buff,
- (char_u *)_("1 more file to edit. Quit anyway?"),
- DIALOG_MSG_SIZE - 1);
+ STRLCPY(buff, _("1 more file to edit. Quit anyway?"),
+ DIALOG_MSG_SIZE);
else
vim_snprintf((char *)buff, DIALOG_MSG_SIZE,
_("%d more files to edit. Quit anyway?"), n);
@@ -5865,7 +5864,7 @@ static void ex_tabs(exarg_T *eap)
msg_putchar(bufIsChanged(wp->w_buffer) ? '+' : ' ');
msg_putchar(' ');
if (buf_spname(wp->w_buffer) != NULL)
- vim_strncpy(IObuff, buf_spname(wp->w_buffer), IOSIZE - 1);
+ STRLCPY(IObuff, buf_spname(wp->w_buffer), IOSIZE);
else
home_replace(wp->w_buffer, wp->w_buffer->b_fname,
IObuff, IOSIZE, TRUE);
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 0b00e458ff..994b2f510f 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -3372,7 +3372,7 @@ addstar (
} else {
retval = xmalloc(len + 4);
if (retval != NULL) {
- vim_strncpy(retval, fname, len);
+ STRLCPY(retval, fname, len + 1);
/*
* Don't add a star to *, ~, ~user, $var or `cmd`.
@@ -3896,10 +3896,10 @@ expand_shellcmd (
l = e - s;
if (l > MAXPATHL - 5)
break;
- vim_strncpy(buf, s, l);
+ STRLCPY(buf, s, l + 1);
add_pathsep(buf);
l = STRLEN(buf);
- vim_strncpy(buf + l, pat, MAXPATHL - 1 - l);
+ STRLCPY(buf + l, pat, MAXPATHL - l);
/* Expand matches in one directory of $PATH. */
ret = expand_wildcards(1, &buf, num_file, file, flags);
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index 2e6cc616e5..f6a052255b 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -307,7 +307,7 @@ vim_findfile_init (
if (!vim_isAbsName(rel_fname) && len + 1 < MAXPATHL) {
/* Make the start dir an absolute path name. */
- vim_strncpy(ff_expand_buffer, rel_fname, len);
+ STRLCPY(ff_expand_buffer, rel_fname, len + 1);
search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer, FALSE);
} else
search_ctx->ffsc_start_dir = vim_strnsave(rel_fname, len);
@@ -1092,7 +1092,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *
// For a URL we only compare the name, otherwise we compare the
// device/inode.
if (path_with_url(fname)) {
- vim_strncpy(ff_expand_buffer, fname, MAXPATHL - 1);
+ STRLCPY(ff_expand_buffer, fname, MAXPATHL);
url = true;
} else {
ff_expand_buffer[0] = NUL;
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index 27ae8c979a..44c67ee8ca 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -1599,7 +1599,7 @@ static void foldAddMarker(linenr_T lnum, char_u *marker, int markerlen)
newline = xmalloc(line_len + markerlen + STRLEN(cms) + 1);
STRCPY(newline, line);
if (p == NULL)
- vim_strncpy(newline + line_len, marker, markerlen);
+ STRLCPY(newline + line_len, marker, markerlen + 1);
else {
STRCPY(newline + line_len, cms);
STRNCPY(newline + line_len + (p - cms), marker, markerlen);
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index b0e5a20506..57b0cf9a31 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -266,7 +266,7 @@ add_buff (
ssize_t len;
if (buf->bh_space >= (int)slen) {
len = STRLEN(buf->bh_curr->b_str);
- vim_strncpy(buf->bh_curr->b_str + len, s, (size_t)slen);
+ STRLCPY(buf->bh_curr->b_str + len, s, slen + 1);
buf->bh_space -= slen;
} else {
if (slen < MINIMAL_SIZE)
@@ -275,7 +275,7 @@ add_buff (
len = slen;
buffblock_T *p = xmalloc(sizeof(buffblock_T) + len);
buf->bh_space = (int)(len - slen);
- vim_strncpy(p->b_str, s, (size_t)slen);
+ STRLCPY(p->b_str, s, slen + 1);
p->b_next = buf->bh_curr->b_next;
buf->bh_curr->b_next = p;
diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c
index 35cce64735..be6d8ee0ee 100644
--- a/src/nvim/hardcopy.c
+++ b/src/nvim/hardcopy.c
@@ -1539,7 +1539,7 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource)
buffer = xmallocz(MAXPATHL);
- vim_strncpy(resource->name, (char_u *)name, 63);
+ STRLCPY(resource->name, name, 64);
/* Look for named resource file in runtimepath */
STRCPY(buffer, "print");
add_pathsep(buffer);
@@ -1748,14 +1748,14 @@ static int prt_open_resource(struct prt_ps_resource_S *resource)
while (!seen_all && prt_next_dsc(&dsc_line)) {
switch (dsc_line.type) {
case PRT_DSC_TITLE_TYPE:
- vim_strncpy(resource->title, dsc_line.string, dsc_line.len);
+ STRLCPY(resource->title, dsc_line.string, dsc_line.len + 1);
seen_title = TRUE;
if (seen_version)
seen_all = TRUE;
break;
case PRT_DSC_VERSION_TYPE:
- vim_strncpy(resource->version, dsc_line.string, dsc_line.len);
+ STRLCPY(resource->version, dsc_line.string, dsc_line.len + 1);
seen_version = TRUE;
if (seen_title)
seen_all = TRUE;
@@ -2160,8 +2160,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
/* Add charset name if not empty */
if (p_mbchar->cmap_charset != NULL) {
- vim_strncpy((char_u *)prt_cmap,
- (char_u *)p_mbchar->cmap_charset, sizeof(prt_cmap) - 3);
+ STRLCPY(prt_cmap, p_mbchar->cmap_charset, sizeof(prt_cmap) - 2);
STRCAT(prt_cmap, "-");
}
} else {
@@ -2170,7 +2169,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
EMSG(_("E674: printmbcharset cannot be empty with multi-byte encoding."));
return FALSE;
}
- vim_strncpy((char_u *)prt_cmap, p_pmcs, sizeof(prt_cmap) - 3);
+ STRLCPY(prt_cmap, p_pmcs, sizeof(prt_cmap) - 2);
STRCAT(prt_cmap, "-");
}
diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c
index 0b3e06070c..ffc00f060a 100644
--- a/src/nvim/if_cscope.c
+++ b/src/nvim/if_cscope.c
@@ -295,7 +295,7 @@ int cs_fgets(char_u *buf, int size)
if ((p = cs_manage_matches(NULL, NULL, -1, Get)) == NULL)
return TRUE;
- vim_strncpy(buf, (char_u *)p, size - 1);
+ STRLCPY(buf, p, size);
return FALSE;
} /* cs_fgets */
@@ -2043,9 +2043,9 @@ static char *cs_resolve_file(int i, char *name)
/* If 'cscoperelative' is set and ppath is not set, use cscope.out
* path in path resolution. */
csdir = xmalloc(MAXPATHL);
- vim_strncpy(csdir, (char_u *)csinfo[i].fname,
+ STRLCPY(csdir, csinfo[i].fname,
path_tail((char_u *)csinfo[i].fname)
- - (char_u *)csinfo[i].fname);
+ - (char_u *)csinfo[i].fname + 1);
len += STRLEN(csdir);
}
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index 068c26958a..1739510f41 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -474,9 +474,9 @@ static void fname2fnum(xfmark_T *fm)
expand_env((char_u *)"~/", NameBuff, MAXPATHL);
len = (int)STRLEN(NameBuff);
- vim_strncpy(NameBuff + len, fm->fname + 2, MAXPATHL - len - 1);
+ STRLCPY(NameBuff + len, fm->fname + 2, MAXPATHL - len);
} else
- vim_strncpy(NameBuff, fm->fname, MAXPATHL - 1);
+ STRLCPY(NameBuff, fm->fname, MAXPATHL);
/* Try to shorten the file name. */
os_dirname(IObuff, IOSIZE);
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index 1bb968b5d0..b3a8df598b 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -677,8 +677,7 @@ static void set_b0_fname(ZERO_BL *b0p, buf_T *buf)
size_t ulen = STRLEN(uname);
size_t flen = STRLEN(b0p->b0_fname);
if (retval == FAIL || ulen + flen > B0_FNAME_SIZE_CRYPT - 1) {
- vim_strncpy(b0p->b0_fname, buf->b_ffname,
- B0_FNAME_SIZE_CRYPT - 1);
+ STRLCPY(b0p->b0_fname, buf->b_ffname, B0_FNAME_SIZE_CRYPT);
} else {
memmove(b0p->b0_fname + ulen + 1, b0p->b0_fname + 1, flen);
memmove(b0p->b0_fname + 1, uname, ulen);
@@ -951,7 +950,7 @@ void ml_recover(void)
smsg((char_u *)_("Using swap file \"%s\""), NameBuff);
if (buf_spname(curbuf) != NULL)
- vim_strncpy(NameBuff, buf_spname(curbuf), MAXPATHL - 1);
+ STRLCPY(NameBuff, buf_spname(curbuf), MAXPATHL);
else
home_replace(NULL, curbuf->b_ffname, NameBuff, MAXPATHL, TRUE);
smsg((char_u *)_("Original file \"%s\""), NameBuff);
@@ -3021,7 +3020,7 @@ int resolve_symlink(char_u *fname, char_u *buf)
return FAIL;
/* Put the result so far in tmp[], starting with the original name. */
- vim_strncpy(tmp, fname, MAXPATHL - 1);
+ STRLCPY(tmp, fname, MAXPATHL);
for (;; ) {
/* Limit symlink depth to 100, catch recursive loops. */
diff --git a/src/nvim/memory.c b/src/nvim/memory.c
index d968aa2bd2..3c6430f311 100644
--- a/src/nvim/memory.c
+++ b/src/nvim/memory.c
@@ -1,6 +1,5 @@
// Various routines dealing with allocation and deallocation of memory.
-#include <stdlib.h>
#include <string.h>
#include "nvim/vim.h"
diff --git a/src/nvim/menu.c b/src/nvim/menu.c
index bfafeb0be2..4f45aa9e34 100644
--- a/src/nvim/menu.c
+++ b/src/nvim/menu.c
@@ -888,7 +888,7 @@ char_u *set_context_in_menu_cmd(expand_T *xp, char_u *cmd, char_u *arg, int forc
menu = root_menu;
if (after_dot != arg) {
path_name = xmalloc(after_dot - arg);
- vim_strncpy(path_name, arg, after_dot - arg - 1);
+ STRLCPY(path_name, arg, after_dot - arg);
}
name = path_name;
while (name != NULL && *name) {
@@ -1004,9 +1004,9 @@ char_u *get_menu_names(expand_T *xp, int idx)
if (menu->modes & expand_modes) {
if (menu->children != NULL) {
if (should_advance)
- vim_strncpy(tbuffer, menu->en_dname, TBUFFER_LEN - 2);
+ STRLCPY(tbuffer, menu->en_dname, TBUFFER_LEN - 1);
else {
- vim_strncpy(tbuffer, menu->dname, TBUFFER_LEN - 2);
+ STRLCPY(tbuffer, menu->dname, TBUFFER_LEN - 1);
if (menu->en_dname == NULL)
should_advance = TRUE;
}
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 1c7687fa69..e099c9b0a5 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -1838,7 +1838,8 @@ store_sb_text (
mp->sb_eol = finish;
mp->sb_msg_col = *sb_col;
mp->sb_attr = attr;
- vim_strncpy(mp->sb_text, *sb_str, s - *sb_str);
+ memcpy(mp->sb_text, *sb_str, s - *sb_str);
+ mp->sb_text[s - *sb_str] = NUL;
if (last_msgchunk == NULL) {
last_msgchunk = mp;
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index cf9a65d2da..7e6dec119b 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -503,7 +503,7 @@ open_line (
+ (second_line_indent > 0 ? second_line_indent : 0) + 1);
allocated = leader; /* remember to free it later */
- vim_strncpy(leader, saved_line, lead_len);
+ STRLCPY(leader, saved_line, lead_len + 1);
/*
* Replace leader with lead_repl, right or left adjusted
@@ -2560,11 +2560,9 @@ void msgmore(long n)
if (pn > p_report) {
if (pn == 1) {
if (n > 0)
- vim_strncpy(msg_buf, (char_u *)_("1 more line"),
- MSG_BUF_LEN - 1);
+ STRLCPY(msg_buf, _("1 more line"), MSG_BUF_LEN);
else
- vim_strncpy(msg_buf, (char_u *)_("1 line less"),
- MSG_BUF_LEN - 1);
+ STRLCPY(msg_buf, _("1 line less"), MSG_BUF_LEN);
} else {
if (n > 0)
vim_snprintf((char *)msg_buf, MSG_BUF_LEN,
@@ -3109,7 +3107,7 @@ char_u *get_env_name(expand_T *xp, int idx)
static char_u name[ENVNAMELEN];
char *envname = os_getenvname_at_index(idx);
if (envname) {
- vim_strncpy(name, (char_u *)envname, ENVNAMELEN - 1);
+ STRLCPY(name, envname, ENVNAMELEN);
free(envname);
return name;
} else {
diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c
index 312154ee2b..c064b4c5e6 100644
--- a/src/nvim/misc2.c
+++ b/src/nvim/misc2.c
@@ -375,7 +375,7 @@ int vim_chdirfile(char_u *fname)
{
char_u dir[MAXPATHL];
- vim_strncpy(dir, fname, MAXPATHL - 1);
+ STRLCPY(dir, fname, MAXPATHL);
*path_tail_with_sep(dir) = NUL;
return os_chdir((char *)dir) == 0 ? OK : FAIL;
}
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 46f70cf23e..4f1cd5d526 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -2222,7 +2222,7 @@ int op_change(oparg_T *oap)
/* Subsequent calls to ml_get() flush the firstline data - take a
* copy of the inserted text. */
ins_text = (char_u *) xmalloc((size_t)(ins_len + 1));
- vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len);
+ STRLCPY(ins_text, firstline + bd.textcol, ins_len + 1);
for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum;
linenr++) {
block_prep(oap, &bd, linenr, TRUE);
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 6b820ea1ba..5690d2c61f 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -3209,7 +3209,7 @@ skip:
}
if (errmsg != NULL) {
- vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
+ STRLCPY(IObuff, _(errmsg), IOSIZE);
i = (int)STRLEN(IObuff) + 2;
if (i + (arg - startarg) < IOSIZE) {
/* append the argument with the error */
@@ -7480,7 +7480,7 @@ option_value2string (
else if ((char_u **)opp->var == &p_pt)
str2specialbuf(p_pt, NameBuff, MAXPATHL);
else
- vim_strncpy(NameBuff, varp, MAXPATHL - 1);
+ STRLCPY(NameBuff, varp, MAXPATHL);
}
}
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index 48bc75cb8e..c8408d78e4 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -39,7 +39,7 @@ int os_dirname(char_u *buf, size_t len)
int errno;
if ((errno = uv_cwd((char *)buf, &len)) != kLibuvSuccess) {
- vim_strncpy(buf, (char_u *)uv_strerror(errno), len - 1);
+ STRLCPY(buf, uv_strerror(errno), len);
return FAIL;
}
return OK;
@@ -123,7 +123,7 @@ static bool is_executable_in_path(const char_u *name)
// Glue together the given directory from $PATH with name and save into
// buf.
- vim_strncpy(buf, (char_u *) path, e - path);
+ STRLCPY(buf, path, e - path + 1);
append_path((char *) buf, (const char *) name, (int)buf_len);
if (is_executable(buf)) {
diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c
index 707a2f5ee9..e687ff3546 100644
--- a/src/nvim/os/users.c
+++ b/src/nvim/os/users.c
@@ -56,7 +56,7 @@ int os_get_uname(uid_t uid, char *s, size_t len)
if ((pw = getpwuid(uid)) != NULL
&& pw->pw_name != NULL && *(pw->pw_name) != NUL) {
- vim_strncpy((char_u *)s, (char_u *)pw->pw_name, len - 1);
+ STRLCPY(s, pw->pw_name, len);
return OK;
}
#endif
diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c
index 18838ddd41..946eaa62a2 100644
--- a/src/nvim/os_unix.c
+++ b/src/nvim/os_unix.c
@@ -409,9 +409,9 @@ int len /* buffer size, only used when name gets longer */
struct stat st2;
/* Verify the inode is equal. */
- vim_strncpy(newname, name, MAXPATHL);
- vim_strncpy(newname + (tail - name), (char_u *)dp->d_name,
- MAXPATHL - (tail - name));
+ STRLCPY(newname, name, MAXPATHL + 1);
+ STRLCPY(newname + (tail - name), dp->d_name,
+ MAXPATHL - (tail - name) + 1);
if (lstat((char *)newname, &st2) >= 0
&& st.st_ino == st2.st_ino
&& st.st_dev == st2.st_dev) {
diff --git a/src/nvim/path.c b/src/nvim/path.c
index cbddde3434..a0859180c9 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -1534,7 +1534,7 @@ vim_FullName (
retval = path_get_absolute_path(fname, buf, len, force);
if (url || retval == FAIL) {
/* something failed; use the file name (truncate when too long) */
- vim_strncpy(buf, fname, len - 1);
+ STRLCPY(buf, fname, len);
}
return retval;
}
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index bfac62de3d..0e40b8eb3e 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -484,9 +484,9 @@ qf_init_ext (
len = (int)STRLEN(p_str);
if (len > CMDBUFFSIZE - 2)
- vim_strncpy(IObuff, p_str, CMDBUFFSIZE - 2);
+ STRLCPY(IObuff, p_str, CMDBUFFSIZE - 1);
else
- vim_strncpy(IObuff, p_str, len);
+ STRLCPY(IObuff, p_str, len + 1);
p_str += len;
} else if (tv->v_type == VAR_LIST) {
@@ -501,7 +501,7 @@ qf_init_ext (
if (len > CMDBUFFSIZE - 2)
len = CMDBUFFSIZE - 2;
- vim_strncpy(IObuff, p_li->li_tv.vval.v_string, len);
+ STRLCPY(IObuff, p_li->li_tv.vval.v_string, len + 1);
p_li = p_li->li_next; /* next item */
}
@@ -509,8 +509,8 @@ qf_init_ext (
/* Get the next line from the supplied buffer */
if (buflnum > lnumlast)
break;
- vim_strncpy(IObuff, ml_get_buf(buf, buflnum++, FALSE),
- CMDBUFFSIZE - 2);
+ STRLCPY(IObuff, ml_get_buf(buf, buflnum++, FALSE),
+ CMDBUFFSIZE - 1);
}
} else if (fgets((char *)IObuff, CMDBUFFSIZE - 2, fd) == NULL)
break;
@@ -609,7 +609,7 @@ restofline:
if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL)
continue;
len = (int)(regmatch.endp[i] - regmatch.startp[i]);
- vim_strncpy(errmsg, regmatch.startp[i], len);
+ STRLCPY(errmsg, regmatch.startp[i], len + 1);
}
if ((i = (int)fmt_ptr->addr[6]) > 0) { /* %r */
if (regmatch.startp[i] == NULL)
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index b37fb1e39d..eab8c58b36 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -6772,7 +6772,7 @@ char_u *reg_submatch(int no)
len = submatch_mmatch->endpos[no].col
- submatch_mmatch->startpos[no].col;
if (round == 2)
- vim_strncpy(retval, s, len);
+ STRLCPY(retval, s, len + 1);
++len;
} else {
/* Multiple lines: take start line from start col, middle
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 0a10def170..0dab25a21a 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -5082,11 +5082,11 @@ win_redr_custom (
/* Make all characters printable. */
p = transstr(buf);
- vim_strncpy(buf, p, sizeof(buf) - 1);
+ len = STRLCPY(buf, p, sizeof(buf));
+ len = (size_t)len < sizeof(buf) ? len : (int)sizeof(buf) - 1;
free(p);
/* fill up with "fillchar" */
- len = (int)STRLEN(buf);
while (width < maxwidth && len < (int)sizeof(buf) - 1) {
len += (*mb_char2bytes)(fillchar, buf + len);
++width;
@@ -7626,7 +7626,7 @@ static void draw_tabline(void)
void get_trans_bufname(buf_T *buf)
{
if (buf_spname(buf) != NULL)
- vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1);
+ STRLCPY(NameBuff, buf_spname(buf), MAXPATHL);
else
home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE);
trans_characters(NameBuff, MAXPATHL);
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 38762b1692..8214d95c00 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -1553,7 +1553,7 @@ static void find_word(matchinf_T *mip, int mode)
if (ptr == mip->mi_word)
(void)spell_casefold(ptr, wlen, fword, MAXWLEN);
else
- vim_strncpy(fword, ptr, endlen[endidxcnt]);
+ STRLCPY(fword, ptr, endlen[endidxcnt] + 1);
}
if (!can_compound(slang, fword, mip->mi_compflags))
continue;
@@ -2274,7 +2274,7 @@ void spell_cat_line(char_u *buf, char_u *line, int maxlen)
n = (int)(p - line) + 1;
if (n < maxlen - 1) {
memset(buf, ' ', n);
- vim_strncpy(buf + n, p, maxlen - 1 - n);
+ STRLCPY(buf + n, p, maxlen - n);
}
}
}
@@ -3064,7 +3064,7 @@ count_common_word (
if (len == -1)
p = word;
else {
- vim_strncpy(buf, word, len);
+ STRLCPY(buf, word, len + 1);
p = buf;
}
@@ -3354,7 +3354,7 @@ static int init_syl_tab(slang_T *slang)
ga_grow(&slang->sl_syl_items, 1);
syl = ((syl_item_T *)slang->sl_syl_items.ga_data)
+ slang->sl_syl_items.ga_len++;
- vim_strncpy(syl->sy_chars, s, l);
+ STRLCPY(syl->sy_chars, s, l + 1);
syl->sy_len = l;
}
return OK;
@@ -3761,7 +3761,7 @@ char_u *did_set_spelllang(win_T *wp)
p = vim_strchr(path_tail(lang), '_');
if (p != NULL && ASCII_ISALPHA(p[1]) && ASCII_ISALPHA(p[2])
&& !ASCII_ISALPHA(p[3])) {
- vim_strncpy(region_cp, p + 1, 2);
+ STRLCPY(region_cp, p + 1, 3);
memmove(p, p + 3, len - (p - lang) - 2);
len -= 3;
region = region_cp;
@@ -3883,7 +3883,7 @@ char_u *did_set_spelllang(win_T *wp)
if (round == 0)
STRCPY(lang, "internal wordlist");
else {
- vim_strncpy(lang, path_tail(spf_name), MAXWLEN);
+ STRLCPY(lang, path_tail(spf_name), MAXWLEN + 1);
p = vim_strchr(lang, '.');
if (p != NULL)
*p = NUL; // truncate at ".encoding.add"
@@ -4004,7 +4004,7 @@ static void use_midword(slang_T *lp, win_T *wp)
bp = vim_strnsave(wp->w_s->b_spell_ismw_mb, n + l);
free(wp->w_s->b_spell_ismw_mb);
wp->w_s->b_spell_ismw_mb = bp;
- vim_strncpy(bp + n, p, l);
+ STRLCPY(bp + n, p, l + 1);
}
p += l;
} else
@@ -4652,7 +4652,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
// times. The affix files that do this have an undocumented
// "S" flag on all but the last block, thus we check for that
// and store it in ah_follows.
- vim_strncpy(key, items[1], AH_KEY_LEN - 1);
+ STRLCPY(key, items[1], AH_KEY_LEN);
hi = hash_find(tp, key);
if (!HASHITEM_EMPTY(hi)) {
cur_aff = HI2AH(hi);
@@ -5223,7 +5223,7 @@ static void process_compflags(spellinfo_T *spin, afffile_T *aff, char_u *compfla
if (flag != 0) {
// Find the flag in the hashtable. If it was used before, use
// the existing ID. Otherwise add a new entry.
- vim_strncpy(key, prevp, p - prevp);
+ STRLCPY(key, prevp, p - prevp + 1);
hi = hash_find(&aff->af_comp, key);
if (!HASHITEM_EMPTY(hi))
id = HI2CI(hi)->ci_newID;
@@ -5612,7 +5612,7 @@ static int get_pfxlist(afffile_T *affile, char_u *afflist, char_u *store_afflist
if (get_affitem(affile->af_flagtype, &p) != 0) {
// A flag is a postponed prefix flag if it appears in "af_pref"
// and it's ID is not zero.
- vim_strncpy(key, prevp, p - prevp);
+ STRLCPY(key, prevp, p - prevp + 1);
hi = hash_find(&affile->af_pref, key);
if (!HASHITEM_EMPTY(hi)) {
id = HI2AH(hi)->ah_newID;
@@ -5643,7 +5643,7 @@ static void get_compflags(afffile_T *affile, char_u *afflist, char