MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / StartSubAllocator

Method StartSubAllocator

Libraries/unrar/suballoc.cpp:79–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77
78
79bool 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
106void SubAllocator::InitSubAllocator()

Callers 2

CleanUpMethod · 0.80
DecodeInitMethod · 0.80

Calls 1

MemoryErrorMethod · 0.80

Tested by

no test coverage detected