diff options
author | oni-link <knil.ino@gmail.com> | 2015-09-30 18:50:20 +0200 |
---|---|---|
committer | oni-link <knil.ino@gmail.com> | 2015-09-30 19:11:07 +0200 |
commit | 0320d86d3bc3967c05677e34a81027ce7fb48551 (patch) | |
tree | fc4dc7783ceceb2d8574caaf3d5ba0131396f3d5 | |
parent | 622ec95c3f793a814b3e7c0ee697c959f5b77332 (diff) | |
download | rneovim-0320d86d3bc3967c05677e34a81027ce7fb48551.tar.gz rneovim-0320d86d3bc3967c05677e34a81027ce7fb48551.tar.bz2 rneovim-0320d86d3bc3967c05677e34a81027ce7fb48551.zip |
garray.c: Prevent ga_concat() using memcpy(NULL,...)
Calling ga_grow(gap, 0) does not reallocate memory for garray gap.
Because of this, gap->ga_data can be NULL after such a call, if gap does
not have memory allocated.
-rw-r--r-- | src/nvim/garray.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/nvim/garray.c b/src/nvim/garray.c index 953eb58841..75c3fb9a73 100644 --- a/src/nvim/garray.c +++ b/src/nvim/garray.c @@ -184,10 +184,12 @@ char_u* ga_concat_strings(const garray_T *gap) FUNC_ATTR_NONNULL_RET void ga_concat(garray_T *gap, const char_u *restrict s) { int len = (int)strlen((char *) s); - ga_grow(gap, len); - char *data = gap->ga_data; - memcpy(data + gap->ga_len, s, (size_t) len); - gap->ga_len += len; + if (len) { + ga_grow(gap, len); + char *data = gap->ga_data; + memcpy(data + gap->ga_len, s, (size_t)len); + gap->ga_len += len; + } } /// Append one byte to a growarray which contains bytes. |