Skip to content

Commit 6277abb

Browse files
Fixes for compilation under Linux gcc and clang.
1 parent 2b3e416 commit 6277abb

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/vk_mem_alloc.h

+17-9
Original file line numberDiff line numberDiff line change
@@ -3060,21 +3060,29 @@ static void VmaWriteMagicValue(void* pData, VkDeviceSize offset)
30603060
{
30613061
uint32_t* pDst = (uint32_t*)((char*)pData + offset);
30623062
const size_t numberCount = VMA_DEBUG_MARGIN / sizeof(uint32_t);
3063-
for(size_t i = 0; i < numberCount; ++i, ++pDst)
3063+
// This condition is to silence clang compiler error: "comparison of unsigned expression < 0 is always false"
3064+
if(numberCount > 0)
30643065
{
3065-
*pDst = VMA_CORRUPTION_DETECTION_MAGIC_VALUE;
3066+
for(size_t i = 0; i < numberCount; ++i, ++pDst)
3067+
{
3068+
*pDst = VMA_CORRUPTION_DETECTION_MAGIC_VALUE;
3069+
}
30663070
}
30673071
}
30683072

30693073
static bool VmaValidateMagicValue(const void* pData, VkDeviceSize offset)
30703074
{
30713075
const uint32_t* pSrc = (const uint32_t*)((const char*)pData + offset);
30723076
const size_t numberCount = VMA_DEBUG_MARGIN / sizeof(uint32_t);
3073-
for(size_t i = 0; i < numberCount; ++i, ++pSrc)
3077+
// This condition is to silence clang compiler error: "comparison of unsigned expression < 0 is always false"
3078+
if(numberCount > 0)
30743079
{
3075-
if(*pSrc != VMA_CORRUPTION_DETECTION_MAGIC_VALUE)
3080+
for(size_t i = 0; i < numberCount; ++i, ++pSrc)
30763081
{
3077-
return false;
3082+
if(*pSrc != VMA_CORRUPTION_DETECTION_MAGIC_VALUE)
3083+
{
3084+
return false;
3085+
}
30783086
}
30793087
}
30803088
return true;
@@ -3513,10 +3521,10 @@ template<typename CmpLess, typename IterT, typename KeyT>
35133521
IterT VmaVectorFindSorted(const IterT& beg, const IterT& end, const KeyT& value)
35143522
{
35153523
CmpLess comparator;
3516-
typename IterT it = VmaBinaryFindFirstNotLess<CmpLess, IterT, KeyT>(
3524+
IterT it = VmaBinaryFindFirstNotLess<CmpLess, IterT, KeyT>(
35173525
beg, end, value, comparator);
35183526
if(it == end ||
3519-
!comparator(*it, value) && !comparator(value, *it))
3527+
(!comparator(*it, value) && !comparator(value, *it)))
35203528
{
35213529
return it;
35223530
}
@@ -8634,8 +8642,8 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest(
86348642
}
86358643

86368644
// There is enough free space at the end after alignment.
8637-
if(index1st == suballocations1st.size() && resultOffset + allocSize + VMA_DEBUG_MARGIN < size ||
8638-
index1st < suballocations1st.size() && resultOffset + allocSize + VMA_DEBUG_MARGIN <= suballocations1st[index1st].offset)
8645+
if((index1st == suballocations1st.size() && resultOffset + allocSize + VMA_DEBUG_MARGIN < size) ||
8646+
(index1st < suballocations1st.size() && resultOffset + allocSize + VMA_DEBUG_MARGIN <= suballocations1st[index1st].offset))
86398647
{
86408648
// Check next suballocations for BufferImageGranularity conflicts.
86418649
// If conflict exists, allocation cannot be made here.

0 commit comments

Comments
 (0)