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
This commit is contained in:
James McCoy
2018-01-23 17:56:50 -05:00
parent 15119f943a
commit 3ff92ba1ee
2 changed files with 5 additions and 1 deletions

View File

@@ -17504,7 +17504,8 @@ static char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl)
// print an error. // print an error.
if (tv->v_type != VAR_LIST && tv->v_type != VAR_NUMBER) { if (tv->v_type != VAR_LIST && tv->v_type != VAR_NUMBER) {
const char *ret = tv_get_string_chk(tv); const char *ret = tv_get_string_chk(tv);
if (ret && (*len = strlen(ret))) { if (ret) {
*len = strlen(ret);
return xmemdupz(ret, (size_t)(*len)); return xmemdupz(ret, (size_t)(*len));
} else { } else {
*len = -1; *len = -1;

View File

@@ -258,6 +258,9 @@ describe('system()', function()
end end
eq(2, eval("1+1")) -- Still alive? eq(2, eval("1+1")) -- Still alive?
end) end)
it('works with an empty string', function()
eq("test\n", eval('system("echo test", "")'))
end)
end) end)
describe('passing a lot of input', function() describe('passing a lot of input', function()