RegionGarbageMap: add an extra overlap check

this shouldn't ever be triggered, but we want to know if it does.
This commit is contained in:
Dylan K. Taylor 2020-09-12 01:38:13 +01:00
parent c2d0605b1e
commit d084b7a34b

View File

@ -69,11 +69,14 @@ final class RegionGarbageMap{
/** @var RegionLocationTableEntry|null $prevEntry */
$prevEntry = null;
foreach($usedMap as $firstSector => $entry){
$expectedStart = ($prevEntry !== null ? $prevEntry->getLastSector() + 1 : RegionLoader::FIRST_SECTOR);
$actualStart = $entry->getFirstSector();
if($expectedStart < $actualStart){
$prevEndPlusOne = ($prevEntry !== null ? $prevEntry->getLastSector() + 1 : RegionLoader::FIRST_SECTOR);
$currentStart = $entry->getFirstSector();
if($prevEndPlusOne < $currentStart){
//found a gap in the table
$garbageMap[$expectedStart] = new RegionLocationTableEntry($expectedStart, $actualStart - $expectedStart, 0);
$garbageMap[$prevEndPlusOne] = new RegionLocationTableEntry($prevEndPlusOne, $currentStart - $prevEndPlusOne, 0);
}elseif($prevEndPlusOne > $currentStart){
//current entry starts inside the previous. This would be a bug since RegionLoader should prevent this
throw new AssumptionFailedError("Overlapping entries detected");
}
$prevEntry = $entry;
}