From d322c3a21ffdad5a47cd295e77eb9e9419865f60 Mon Sep 17 00:00:00 2001 From: Rocco Corsi <5201151+rcorsi@users.noreply.github.com> Date: Tue, 22 Jul 2025 12:23:13 -0400 Subject: [PATCH] LibGfx: VulkanContext coverity reports integer_overflow on index Coverity static analysis reports that the code that scans the queue families for one that has the graphics bit, can be -1 if none are found, which could cause a problem when the -1 (signed) value is used later as an index in a uint32_t (unsigned) variable. Its not immediately clear how often this could occur, not finding a queue family with the graphics bit, but adding some protecting just in case. --- Libraries/LibGfx/VulkanContext.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Libraries/LibGfx/VulkanContext.cpp b/Libraries/LibGfx/VulkanContext.cpp index c7f0bb0b6a0..c5e884003b6 100644 --- a/Libraries/LibGfx/VulkanContext.cpp +++ b/Libraries/LibGfx/VulkanContext.cpp @@ -75,14 +75,19 @@ static ErrorOr create_logical_device(VkPhysicalDevice physical_device) queue_families.resize(queue_family_count); vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &queue_family_count, queue_families.data()); - int graphics_queue_family_index = -1; - for (int i = 0; i < static_cast(queue_families.size()); i++) { - if (queue_families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { - graphics_queue_family_index = i; + bool graphics_queue_family_found = false; + uint32_t graphics_queue_family_index = 0; + for (; graphics_queue_family_index < queue_families.size(); ++graphics_queue_family_index) { + if (queue_families[graphics_queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) { + graphics_queue_family_found = true; break; } } + if (!graphics_queue_family_found) { + return Error::from_string_literal("Graphics queue family not found"); + } + VkDeviceQueueCreateInfo queue_create_info {}; queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; queue_create_info.queueFamilyIndex = graphics_queue_family_index;