diff options
author | ZyX <kp-pav@yandex.ru> | 2016-02-09 03:20:16 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2016-04-18 02:47:13 +0300 |
commit | 77776b09c684bc2a0c42114fce5a8b04409ec91d (patch) | |
tree | de255689c5cc709b88e065b1a99bffed0e310ac0 /src/nvim/eval/encode.c | |
parent | c27395ddc84952b94118de94af4c33f56f6beca5 (diff) | |
download | rneovim-77776b09c684bc2a0c42114fce5a8b04409ec91d.tar.gz rneovim-77776b09c684bc2a0c42114fce5a8b04409ec91d.tar.bz2 rneovim-77776b09c684bc2a0c42114fce5a8b04409ec91d.zip |
eval/encode: Fix writing strings starting with NL to list
Error [found][1] by oni-link.
[1]: https://github.com/neovim/neovim/pull/4131/files#r52239384
Diffstat (limited to 'src/nvim/eval/encode.c')
-rw-r--r-- | src/nvim/eval/encode.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index 8280889fbe..6026189235 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -79,11 +79,9 @@ int encode_list_write(void *data, const char *buf, size_t len) do { const char *line_start = line_end; line_end = xmemscan(line_start, NL, (size_t) (end - line_start)); - if (line_end == line_start) { - list_append_allocated_string(list, NULL); - } else { + char *str = NULL; + if (line_end != line_start) { const size_t line_length = (size_t) (line_end - line_start); - char *str; if (li == NULL) { str = xmemdupz(line_start, line_length); } else { @@ -93,7 +91,7 @@ int encode_list_write(void *data, const char *buf, size_t len) li->li_tv.vval.v_string = xrealloc(li->li_tv.vval.v_string, li_len + line_length + 1); str = (char *) li->li_tv.vval.v_string + li_len; - memmove(str, line_start, line_length); + memcpy(str, line_start, line_length); str[line_length] = 0; } for (size_t i = 0; i < line_length; i++) { @@ -101,14 +99,14 @@ int encode_list_write(void *data, const char *buf, size_t len) str[i] = NL; } } - if (li == NULL) { - list_append_allocated_string(list, str); - } else { - li = NULL; - } - if (line_end == end - 1) { - list_append_allocated_string(list, NULL); - } + } + if (li == NULL) { + list_append_allocated_string(list, str); + } else { + li = NULL; + } + if (line_end == end - 1) { + list_append_allocated_string(list, NULL); } line_end++; } while (line_end < end); |