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.
This commit is contained in:
Rocco Corsi 2025-07-22 12:23:13 -04:00 committed by Alexander Kalenik
parent bc4112bf18
commit d322c3a21f

View File

@ -75,14 +75,19 @@ static ErrorOr<VkDevice> 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<int>(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;