diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-05-03 09:29:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-03 09:29:55 +0800 |
commit | 13520aae163bfc243fc050cf16b89082c0896eaf (patch) | |
tree | 7487c15a5539ba28ebeb10035587f4b870bbc70f /src/nvim/api/private/helpers.c | |
parent | cf474021ed44f197da3c67214fcb95a20886799c (diff) | |
download | rneovim-13520aae163bfc243fc050cf16b89082c0896eaf.tar.gz rneovim-13520aae163bfc243fc050cf16b89082c0896eaf.tar.bz2 rneovim-13520aae163bfc243fc050cf16b89082c0896eaf.zip |
fix(coverity): use xstrndup() instead of vim_strsave() (#18363)
Diffstat (limited to 'src/nvim/api/private/helpers.c')
-rw-r--r-- | src/nvim/api/private/helpers.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index a07b5b6e3a..a89a254f20 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -488,6 +488,16 @@ String cstr_to_string(const char *str) }; } +/// Copies a String to an allocated, NUL-terminated C string. +/// +/// @param str the String to copy +/// @return the resulting C string +char *string_to_cstr(String str) + FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT +{ + return xstrndup(str.data, str.size); +} + /// Copies buffer to an allocated String. /// The resulting string is also NUL-terminated, to facilitate interoperating /// with code using C strings. @@ -628,7 +638,7 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod (char_u *)rhs.data, rhs.size, lua_funcref, CPO_TO_CPO_FLAGS, &parsed_args); if (opts != NULL && opts->desc.type == kObjectTypeString) { - parsed_args.desc = xstrdup(opts->desc.data.string.data); + parsed_args.desc = string_to_cstr(opts->desc.data.string); } else { parsed_args.desc = NULL; } |