使用有符号整数比较,便于判断堆溢出

This commit is contained in:
大石头X2 2017-02-20 23:25:04 +08:00
parent cbec1ec867
commit de2db57d4d
1 changed files with 2 additions and 2 deletions

View File

@ -53,13 +53,13 @@ void* Heap::Alloc(uint size)
size = (size+MEMORY_ALIGN-1) & (~(MEMORY_ALIGN-1));
void* ret = nullptr;
auto need = size + sizeof(MemoryBlock);
int need = size + sizeof(MemoryBlock);
SmartIRQ irq;
for(auto mcb=(MemoryBlock*)Address; mcb->Next!=nullptr; mcb=mcb->Next)
{
// 找到一块满足大小的内存块
auto free = (uint)mcb->Next - (uint)mcb - mcb->Used;
int free = (uint)mcb->Next - (uint)mcb - mcb->Used;
if(free >= need)
{
// 割一块出来