From: Rhys Perry Date: Fri, 14 Aug 2020 16:40:13 +0000 (+0100) Subject: radv: fix null memcpy and zero-sized malloc X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b553c7dd96af6f79b94cf1729c5e151e5b857e6b;p=mesa.git radv: fix null memcpy and zero-sized malloc Signed-off-by: Rhys Perry Reviewed-by: Samuel Pitoiset Part-of: --- 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; }