diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-01-23 21:50:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-23 21:50:41 +0100 |
commit | 5892aab1b54b115cc3e74cb0ac59b0034627bf4e (patch) | |
tree | 974ccd5d14bb258403f3ec274ac93e8dfd651ca6 /src/nvim/path.c | |
parent | d4b931deacf61528e902623d38d0f4d314bc1839 (diff) | |
parent | b70a5cdd49ecd5f3fe749c1c66a169fee828c66e (diff) | |
download | rneovim-5892aab1b54b115cc3e74cb0ac59b0034627bf4e.tar.gz rneovim-5892aab1b54b115cc3e74cb0ac59b0034627bf4e.tar.bz2 rneovim-5892aab1b54b115cc3e74cb0ac59b0034627bf4e.zip |
Merge #5996 from justinmk/coverity-133845
xstrlcat() + coverity fixes
Diffstat (limited to 'src/nvim/path.c')
-rw-r--r-- | src/nvim/path.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c index 3d1def8dd4..7e1183d5db 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -391,15 +391,22 @@ char *concat_fnames_realloc(char *fname1, const char *fname2, bool sep) fname2, len2, sep); } -/* - * Add a path separator to a file name, unless it already ends in a path - * separator. - */ -void add_pathsep(char *p) +/// Adds a path separator to a filename, unless it already ends in one. +/// +/// @return `true` if the path separator was added or already existed. +/// `false` if the filename is too long. +bool add_pathsep(char *p) FUNC_ATTR_NONNULL_ALL { - if (*p != NUL && !after_pathsep(p, p + strlen(p))) - strcat(p, PATHSEPSTR); + const size_t len = strlen(p); + if (*p != NUL && !after_pathsep(p, p + len)) { + const size_t pathsep_len = sizeof(PATHSEPSTR); + if (len > MAXPATHL - pathsep_len) { + return false; + } + memcpy(p + len, PATHSEPSTR, pathsep_len); + } + return true; } /// Get an allocated copy of the full path to a file. |