Skip to content

Commit fbd9e6e

Browse files
Code improvements based on static analysis
See #488
1 parent 089e0eb commit fbd9e6e

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

include/vk_mem_alloc.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3982,7 +3982,7 @@ VmaBufferImageUsage::VmaBufferImageUsage(const VkBufferCreateInfo &createInfo,
39823982
// of the VK_KHR_maintenance5 extension.
39833983
const VkBufferUsageFlags2CreateInfoKHR* const usageFlags2 =
39843984
VmaPnextChainFind<VkBufferUsageFlags2CreateInfoKHR>(&createInfo, VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO_KHR);
3985-
if(usageFlags2 != 0)
3985+
if(usageFlags2 != VMA_NULL)
39863986
{
39873987
this->Value = usageFlags2->usage;
39883988
return;
@@ -10153,7 +10153,6 @@ struct VmaVirtualBlock_T
1015310153
explicit VmaVirtualBlock_T(const VmaVirtualBlockCreateInfo& createInfo);
1015410154
~VmaVirtualBlock_T();
1015510155

10156-
VkResult Init() { return VK_SUCCESS; }
1015710156
bool IsEmpty() const { return m_Metadata->IsEmpty(); }
1015810157
void Free(VmaVirtualAllocation allocation) { m_Metadata->Free((VmaAllocHandle)allocation); }
1015910158
void SetAllocationUserData(VmaVirtualAllocation allocation, void* userData) { m_Metadata->SetAllocationUserData((VmaAllocHandle)allocation, userData); }
@@ -11412,7 +11411,7 @@ VkResult VmaBlockVector::AllocatePage(
1141211411
{
1141311412
const bool isUpperAddress = (createInfo.flags & VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT) != 0;
1141411413

11415-
VkDeviceSize freeMemory;
11414+
VkDeviceSize freeMemory = 0;
1141611415
{
1141711416
const uint32_t heapIndex = m_hAllocator->MemoryTypeIndexToHeapIndex(m_MemoryTypeIndex);
1141811417
VmaBudget heapBudget = {};
@@ -11993,6 +11992,8 @@ VmaDefragmentationContext_T::VmaDefragmentationContext_T(
1199311992
m_AlgorithmState = vma_new_array(hAllocator, StateExtensive, m_BlockVectorCount);
1199411993
}
1199511994
break;
11995+
default:
11996+
; // Do nothing.
1199611997
}
1199711998
}
1199811999

@@ -12089,11 +12090,10 @@ VkResult VmaDefragmentationContext_T::DefragmentPassEnd(VmaDefragmentationPassMo
1208912090
size_t currentCount = 0;
1209012091
VkDeviceSize freedBlockSize = 0;
1209112092

12092-
uint32_t vectorIndex;
12093-
VmaBlockVector* vector;
12093+
uint32_t vectorIndex = 0;
12094+
VmaBlockVector* vector = VMA_NULL;
1209412095
if (m_PoolBlockVector != VMA_NULL)
1209512096
{
12096-
vectorIndex = 0;
1209712097
vector = m_PoolBlockVector;
1209812098
}
1209912099
else
@@ -12178,7 +12178,7 @@ VkResult VmaDefragmentationContext_T::DefragmentPassEnd(VmaDefragmentationPassMo
1217812178
}
1217912179
freedBlockSize *= prevCount - currentCount;
1218012180

12181-
VkDeviceSize dstBlockSize;
12181+
VkDeviceSize dstBlockSize = SIZE_MAX;
1218212182
{
1218312183
VmaMutexLockRead lock(vector->GetMutex(), vector->GetAllocator()->m_UseMutex);
1218412184
dstBlockSize = move.dstTmpAllocation->GetBlock()->m_pMetadata->GetSize();
@@ -12354,8 +12354,7 @@ VmaDefragmentationContext_T::CounterStatus VmaDefragmentationContext_T::CheckCou
1235412354
{
1235512355
if (++m_IgnoredAllocs < MAX_ALLOCS_TO_IGNORE)
1235612356
return CounterStatus::Ignore;
12357-
else
12358-
return CounterStatus::End;
12357+
return CounterStatus::End;
1235912358
}
1236012359

1236112360
m_IgnoredAllocs = 0;
@@ -14574,11 +14573,9 @@ VkResult VmaAllocator_T::BindVulkanBuffer(
1457414573
bindBufferMemoryInfo.memoryOffset = memoryOffset;
1457514574
return (*m_VulkanFunctions.vkBindBufferMemory2KHR)(m_hDevice, 1, &bindBufferMemoryInfo);
1457614575
}
14577-
else
1457814576
#endif // #if VMA_VULKAN_VERSION >= 1001000 || VMA_BIND_MEMORY2
14579-
{
14580-
return VK_ERROR_EXTENSION_NOT_PRESENT;
14581-
}
14577+
14578+
return VK_ERROR_EXTENSION_NOT_PRESENT;
1458214579
}
1458314580
else
1458414581
{
@@ -15543,7 +15540,7 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForBufferInfo(
1554315540

1554415541
const VkDevice hDev = allocator->m_hDevice;
1554515542
const VmaVulkanFunctions* funcs = &allocator->GetVulkanFunctions();
15546-
VkResult res;
15543+
VkResult res = VK_SUCCESS;
1554715544

1554815545
#if VMA_KHR_MAINTENANCE4 || VMA_VULKAN_VERSION >= 1003000
1554915546
if(funcs->vkGetDeviceBufferMemoryRequirements)
@@ -15595,7 +15592,7 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaFindMemoryTypeIndexForImageInfo(
1559515592

1559615593
const VkDevice hDev = allocator->m_hDevice;
1559715594
const VmaVulkanFunctions* funcs = &allocator->GetVulkanFunctions();
15598-
VkResult res;
15595+
VkResult res = VK_SUCCESS;
1559915596

1560015597
#if VMA_KHR_MAINTENANCE4 || VMA_VULKAN_VERSION >= 1003000
1560115598
if(funcs->vkGetDeviceImageMemoryRequirements)
@@ -16712,13 +16709,19 @@ VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateVirtualBlock(
1671216709
VMA_DEBUG_LOG("vmaCreateVirtualBlock");
1671316710
VMA_DEBUG_GLOBAL_MUTEX_LOCK;
1671416711
*pVirtualBlock = vma_new(pCreateInfo->pAllocationCallbacks, VmaVirtualBlock_T)(*pCreateInfo);
16712+
return VK_SUCCESS;
16713+
16714+
/*
16715+
Code for the future if we ever need a separate Init() method that could fail:
16716+
1671516717
VkResult res = (*pVirtualBlock)->Init();
1671616718
if(res < 0)
1671716719
{
1671816720
vma_delete(pCreateInfo->pAllocationCallbacks, *pVirtualBlock);
1671916721
*pVirtualBlock = VK_NULL_HANDLE;
1672016722
}
1672116723
return res;
16724+
*/
1672216725
}
1672316726

1672416727
VMA_CALL_PRE void VMA_CALL_POST vmaDestroyVirtualBlock(VmaVirtualBlock VMA_NULLABLE virtualBlock)

0 commit comments

Comments
 (0)