From 8373aaf44e6a64dda135a11f275f4616afa23b63 Mon Sep 17 00:00:00 2001 From: oni-link Date: Sat, 19 Dec 2015 11:29:39 +0100 Subject: helpers.c: Handle msgpack str/bin objects with length 0 correctly When converting a msgpack object to a String object, strings (and byte arrays) with length 0 are handled as errors. This is fixed by always using the msgpack data pointer as a valid pointer. For a NULL pointer there is nothing to copy. Test by @snoe Fixes #3844 --- src/nvim/msgpack_rpc/helpers.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/msgpack_rpc/helpers.c b/src/nvim/msgpack_rpc/helpers.c index a119c4653a..5ef81721d4 100644 --- a/src/nvim/msgpack_rpc/helpers.c +++ b/src/nvim/msgpack_rpc/helpers.c @@ -94,10 +94,9 @@ bool msgpack_rpc_to_string(msgpack_object *obj, String *arg) FUNC_ATTR_NONNULL_ALL { if (obj->type == MSGPACK_OBJECT_BIN || obj->type == MSGPACK_OBJECT_STR) { - if (obj->via.bin.ptr == NULL) { - return false; - } - arg->data = xmemdupz(obj->via.bin.ptr, obj->via.bin.size); + arg->data = obj->via.bin.ptr != NULL + ? xmemdupz(obj->via.bin.ptr, obj->via.bin.size) + : NULL; arg->size = obj->via.bin.size; return true; } -- cgit