aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/path.c
diff options
context:
space:
mode:
authorcztchoice <cztchoice@gmail.com>2015-10-17 12:18:26 +0800
committerJustin M. Keyes <justinkz@gmail.com>2017-01-23 15:49:36 +0100
commit7c7c5a80a46b38067e8288e1e3ccd2b9c7c73b6e (patch)
tree40e03016450f2dc0a0f5f03adbe7a9abdad40e9a /src/nvim/path.c
parent6e75bb5cbbf172bf586b3326ac43bad219ae26a3 (diff)
downloadrneovim-7c7c5a80a46b38067e8288e1e3ccd2b9c7c73b6e.tar.gz
rneovim-7c7c5a80a46b38067e8288e1e3ccd2b9c7c73b6e.tar.bz2
rneovim-7c7c5a80a46b38067e8288e1e3ccd2b9c7c73b6e.zip
add_pathsep(): Return false if filename is too long.
References #3042
Diffstat (limited to 'src/nvim/path.c')
-rw-r--r--src/nvim/path.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c
index cdb16dbef1..7e1183d5db 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -391,19 +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
{
const size_t len = strlen(p);
- const size_t pathsep_len = sizeof(PATHSEPSTR);
- assert(len < MAXPATHL - pathsep_len);
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.