aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2018-01-23 17:56:50 -0500
committerJames McCoy <jamessan@jamessan.com>2018-01-23 17:56:50 -0500
commit3ff92ba1ee54a9400aac143f4d98d356dc6a8321 (patch)
tree97bae51783d202fbe0bd447b5f5f4742679b89ed
parent15119f943ab8c2d089f45969da06b6b58b4d0036 (diff)
downloadrneovim-3ff92ba1ee54a9400aac143f4d98d356dc6a8321.tar.gz
rneovim-3ff92ba1ee54a9400aac143f4d98d356dc6a8321.tar.bz2
rneovim-3ff92ba1ee54a9400aac143f4d98d356dc6a8321.zip
eval: save_tv_as_string: Correctly handle an empty string
When tv_get_string_chk returns a non-NULL value, we have a valid string. Propagating an error state (*len = -1, NULL return) for an empty string is invalid. Closes #6554
-rw-r--r--src/nvim/eval.c3
-rw-r--r--test/functional/eval/system_spec.lua3
2 files changed, 5 insertions, 1 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index f663d13c55..07a9e9286d 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -17504,7 +17504,8 @@ static char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl)
// print an error.
if (tv->v_type != VAR_LIST && tv->v_type != VAR_NUMBER) {
const char *ret = tv_get_string_chk(tv);
- if (ret && (*len = strlen(ret))) {
+ if (ret) {
+ *len = strlen(ret);
return xmemdupz(ret, (size_t)(*len));
} else {
*len = -1;
diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua
index 66d569416e..77e7424452 100644
--- a/test/functional/eval/system_spec.lua
+++ b/test/functional/eval/system_spec.lua
@@ -258,6 +258,9 @@ describe('system()', function()
end
eq(2, eval("1+1")) -- Still alive?
end)
+ it('works with an empty string', function()
+ eq("test\n", eval('system("echo test", "")'))
+ end)
end)
describe('passing a lot of input', function()