Mesa (master): radv: fix null memcpy and zero-sized malloc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Aug 20 11:09:52 UTC 2020


Module: Mesa
Branch: master
Commit: b553c7dd96af6f79b94cf1729c5e151e5b857e6b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b553c7dd96af6f79b94cf1729c5e151e5b857e6b

Author: Rhys Perry <pendingchaos02 at gmail.com>
Date:   Fri Aug 14 17:40:13 2020 +0100

radv: fix null memcpy and zero-sized malloc

Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6206>

---

 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;
 }



More information about the mesa-commit mailing list