aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/vim.c
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-05-23 15:49:19 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-05-23 15:49:19 -0300
commit677d30d7966dd2766bbf20665791c568dacc427a (patch)
treede8f5411829ee7c17ad77f6281316624243b05c9 /src/nvim/api/vim.c
parentc6483aa2fae07654f8a874a0c479916de33ec592 (diff)
downloadrneovim-677d30d7966dd2766bbf20665791c568dacc427a.tar.gz
rneovim-677d30d7966dd2766bbf20665791c568dacc427a.tar.bz2
rneovim-677d30d7966dd2766bbf20665791c568dacc427a.zip
API: Bugfix: Use 0-terminated string in vim_strwidth
While the mb_string2cells function accepts a length parameter, it only seems to work properly with 0-terminated strings, since valgrind reports a conditional jump that depends on uninitialized values(means it reads after the string boundaries which could result in overflows or wrong results)
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r--src/nvim/api/vim.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 5796d7bc0e..1f335cf5e0 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -73,7 +73,10 @@ Integer vim_strwidth(String str, Error *err)
return 0;
}
- return mb_string2cells((char_u *)str.data, (int)str.size);
+ char *buf = xstrndup(str.data, str.size);
+ Integer rv = mb_string2cells((char_u *)buf, -1);
+ free(buf);
+ return rv;
}
StringArray vim_list_runtime_paths(void)