| 77 | |
| 78 | |
| 79 | bool SubAllocator::StartSubAllocator(int SASize) |
| 80 | { |
| 81 | uint t=SASize << 20; |
| 82 | if (SubAllocatorSize == t) |
| 83 | return true; |
| 84 | StopSubAllocator(); |
| 85 | |
| 86 | // Original algorithm expects FIXED_UNIT_SIZE, but actual structure size |
| 87 | // can be larger. So let's recalculate the allocated size and add two more |
| 88 | // units: one as reserve for HeapEnd overflow checks and another |
| 89 | // to provide the space to correctly align UnitsStart. |
| 90 | uint AllocSize=t/FIXED_UNIT_SIZE*UNIT_SIZE+2*UNIT_SIZE; |
| 91 | if ((HeapStart=(byte *)malloc(AllocSize)) == NULL) |
| 92 | { |
| 93 | ErrHandler.MemoryError(); |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | // HeapEnd did not present in original algorithm. We added it to control |
| 98 | // invalid memory access attempts when processing corrupt archived data. |
| 99 | HeapEnd=HeapStart+AllocSize-UNIT_SIZE; |
| 100 | |
| 101 | SubAllocatorSize=t; |
| 102 | return true; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | void SubAllocator::InitSubAllocator() |
no test coverage detected