diff options
author | Sean Dewar <6256228+seandewar@users.noreply.github.com> | 2024-03-03 22:33:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-03 22:33:28 +0000 |
commit | bf0c69e50410a77d3a7b1a0760f2e574e85d028a (patch) | |
tree | 15a2771d9d44681e3c3a9603619e088d5dbf47db | |
parent | 3971797be125a958432fb439575ae31b544f4083 (diff) | |
download | rneovim-bf0c69e50410a77d3a7b1a0760f2e574e85d028a.tar.gz rneovim-bf0c69e50410a77d3a7b1a0760f2e574e85d028a.tar.bz2 rneovim-bf0c69e50410a77d3a7b1a0760f2e574e85d028a.zip |
fix(eval): correct failure return value for readfile/blob (#27722)
Currently returns 0 on failure, but should return an empty list (or blob).
Regressed in the big blob port of '21 (#15211).
-rw-r--r-- | src/nvim/eval/funcs.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 3b387e3fd6..fa57d41032 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -6005,6 +6005,12 @@ static void read_file_or_blob(typval_T *argvars, typval_T *rettv, bool always_bl } } + if (blob) { + tv_blob_alloc_ret(rettv); + } else { + tv_list_alloc_ret(rettv, kListLenUnknown); + } + // Always open the file in binary mode, library functions have a mind of // their own about CR-LF conversion. const char *const fname = tv_get_string(&argvars[0]); @@ -6019,7 +6025,6 @@ static void read_file_or_blob(typval_T *argvars, typval_T *rettv, bool always_bl } if (blob) { - tv_blob_alloc_ret(rettv); if (read_blob(fd, rettv, offset, size) == FAIL) { semsg(_(e_notread), fname); } @@ -6027,7 +6032,7 @@ static void read_file_or_blob(typval_T *argvars, typval_T *rettv, bool always_bl return; } - list_T *const l = tv_list_alloc_ret(rettv, kListLenUnknown); + list_T *const l = rettv->vval.v_list; while (maxline < 0 || tv_list_len(l) < maxline) { int readlen = (int)fread(buf, 1, (size_t)io_size, fd); |