aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/private/helpers.c
diff options
context:
space:
mode:
authorNicolas Hillegeer <nicolas@hillegeer.com>2014-05-30 18:45:11 +0200
committerNicolas Hillegeer <nicolas@hillegeer.com>2014-06-08 19:21:35 +0200
commit563698b2dc3f280b6d0d1e9156d0f1d4a4f756c4 (patch)
tree5191a63055d90ec0fbb4a73f3ab4dd6f26a0f93c /src/nvim/api/private/helpers.c
parente1793949abd6e5a304ee48aaecc2c33d89a2a48d (diff)
downloadrneovim-563698b2dc3f280b6d0d1e9156d0f1d4a4f756c4.tar.gz
rneovim-563698b2dc3f280b6d0d1e9156d0f1d4a4f756c4.tar.bz2
rneovim-563698b2dc3f280b6d0d1e9156d0f1d4a4f756c4.zip
api: also NUL-terminate Strings made from cstrs
I believe we can now mostly assume that all encountered String's data members are safe to pass into functions that accept C strings. That should simplify interop with C string code.
Diffstat (limited to 'src/nvim/api/private/helpers.c')
-rw-r--r--src/nvim/api/private/helpers.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index 11de50455b..d946e60dd4 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -352,19 +352,22 @@ tabpage_T * find_tab(Tabpage tabpage, Error *err)
return rv;
}
-/// Copies a C string into a String (binary safe string, characters + length)
+/// Copies a C string into a String (binary safe string, characters + length).
+/// The resulting string is also NUL-terminated, to facilitate interoperating
+/// with code using C strings.
///
/// @param str the C string to copy
-/// @return the resulting String, if the input string was NULL, then an
+/// @return the resulting String, if the input string was NULL, an
/// empty String is returned
-String cstr_to_string(const char *str) {
+String cstr_to_string(const char *str)
+{
if (str == NULL) {
return (String) STRING_INIT;
}
size_t len = strlen(str);
return (String) {
- .data = xmemdup(str, len),
+ .data = xmemdupz(str, len),
.size = len
};
}