From b553c7dd96af6f79b94cf1729c5e151e5b857e6b Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Fri, 14 Aug 2020 17:40:13 +0100 Subject: [PATCH] radv: fix null memcpy and zero-sized malloc Signed-off-by: Rhys Perry Reviewed-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/radv_descriptor_set.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/amd/vulkan/radv_descriptor_set.c b/src/amd/vulkan/radv_descriptor_set.c index 435c867dd02..e4634eed663 100644 --- a/src/amd/vulkan/radv_descriptor_set.c +++ b/src/amd/vulkan/radv_descriptor_set.c @@ -57,13 +57,14 @@ static int binding_compare(const void* av, const void *bv) static VkDescriptorSetLayoutBinding * create_sorted_bindings(const VkDescriptorSetLayoutBinding *bindings, unsigned count) { - VkDescriptorSetLayoutBinding *sorted_bindings = malloc(count * sizeof(VkDescriptorSetLayoutBinding)); + VkDescriptorSetLayoutBinding *sorted_bindings = malloc(MAX2(count * sizeof(VkDescriptorSetLayoutBinding), 1)); if (!sorted_bindings) return NULL; - memcpy(sorted_bindings, bindings, count * sizeof(VkDescriptorSetLayoutBinding)); - - qsort(sorted_bindings, count, sizeof(VkDescriptorSetLayoutBinding), binding_compare); + if (count) { + memcpy(sorted_bindings, bindings, count * sizeof(VkDescriptorSetLayoutBinding)); + qsort(sorted_bindings, count, sizeof(VkDescriptorSetLayoutBinding), binding_compare); + } return sorted_bindings; } -- 2.30.2