aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_cmds.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-01-26 14:33:03 +0100
committerGitHub <noreply@github.com>2017-01-26 14:33:03 +0100
commit59fd0c4132f06a76c460f46ec93fce7b7f1d6f08 (patch)
tree0a6eaf861fa7406c9cd06ffd61dc37e84b051975 /src/nvim/ex_cmds.c
parentf78982620a48dc76bbd3635300650d06ced24aab (diff)
downloadrneovim-59fd0c4132f06a76c460f46ec93fce7b7f1d6f08.tar.gz
rneovim-59fd0c4132f06a76c460f46ec93fce7b7f1d6f08.tar.bz2
rneovim-59fd0c4132f06a76c460f46ec93fce7b7f1d6f08.zip
refactor: Remove strncpy/STRNCPY. (#6008)
Closes #731 References #851 Note: This does not remove some intentional legacy usages of strncpy. - memcpy isn't equivalent because it doesn't check the string length of `src`, and doesn't zero-out the remainder of `dst`. - xstrlcpy isn't equivalent because it doesn't zero-out the remainder of `dst`. Some Vim logic depends on that (e.g. ex_append which calls vim_strnsave). Helped-by: Douglas Schneider <ds3@ualberta.ca> Helped-by: oni-link <knil.ino@gmail.com> Helped-by: James McCoy <jamessan@jamessan.com>
Diffstat (limited to 'src/nvim/ex_cmds.c')
-rw-r--r--src/nvim/ex_cmds.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 56919db024..e6e85a3f6c 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -357,12 +357,12 @@ static int sort_compare(const void *s1, const void *s2)
// We need to copy one line into "sortbuf1", because there is no
// guarantee that the first pointer becomes invalid when obtaining the
// second one.
- STRNCPY(sortbuf1, ml_get(l1.lnum) + l1.st_u.line.start_col_nr,
- l1.st_u.line.end_col_nr - l1.st_u.line.start_col_nr + 1);
- sortbuf1[l1.st_u.line.end_col_nr - l1.st_u.line.start_col_nr] = 0;
- STRNCPY(sortbuf2, ml_get(l2.lnum) + l2.st_u.line.start_col_nr,
- l2.st_u.line.end_col_nr - l2.st_u.line.start_col_nr + 1);
- sortbuf2[l2.st_u.line.end_col_nr - l2.st_u.line.start_col_nr] = 0;
+ memcpy(sortbuf1, ml_get(l1.lnum) + l1.st_u.line.start_col_nr,
+ l1.st_u.line.end_col_nr - l1.st_u.line.start_col_nr + 1);
+ sortbuf1[l1.st_u.line.end_col_nr - l1.st_u.line.start_col_nr] = NUL;
+ memcpy(sortbuf2, ml_get(l2.lnum) + l2.st_u.line.start_col_nr,
+ l2.st_u.line.end_col_nr - l2.st_u.line.start_col_nr + 1);
+ sortbuf2[l2.st_u.line.end_col_nr - l2.st_u.line.start_col_nr] = NUL;
result = sort_ic ? STRICMP(sortbuf1, sortbuf2)
: STRCMP(sortbuf1, sortbuf2);
@@ -1404,7 +1404,7 @@ char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp)
: "(%s)";
vim_snprintf(buf, len, fmt, (char *)cmd);
} else {
- strncpy(buf, (char *) cmd, len);
+ xstrlcpy(buf, (char *)cmd, len);
}
if (itmp != NULL) {
@@ -1414,7 +1414,7 @@ char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp)
#else
// For shells that don't understand braces around commands, at least allow
// the use of commands in a pipe.
- strncpy(buf, cmd, len);
+ xstrlcpy(buf, cmd, len);
if (itmp != NULL) {
// If there is a pipe, we have to put the '<' in front of it.
// Don't do this when 'shellquote' is not empty, otherwise the