Make use of Utils::assumeNotFalse() in a bunch of places

I've stuck to only doing this in the places where I'm sure we should never get false back. Other places I'm less sure of (and I found more bugs along the way).
This commit is contained in:
Dylan K. Taylor
2021-12-08 19:33:45 +00:00
parent 8b73549355
commit 889d048ca3
26 changed files with 67 additions and 171 deletions

View File

@ -25,6 +25,7 @@ namespace pocketmine\resourcepacks;
use Ahc\Json\Comment as CommentedJsonDecoder;
use pocketmine\resourcepacks\json\Manifest;
use pocketmine\utils\Utils;
use function assert;
use function fclose;
use function feof;
@ -73,7 +74,7 @@ class ZippedResourcePack implements ResourcePack{
$manifestPath = null;
$manifestIdx = null;
for($i = 0; $i < $archive->numFiles; ++$i){
$name = $archive->getNameIndex($i);
$name = Utils::assumeNotFalse($archive->getNameIndex($i), "This index should be valid");
if(
($manifestPath === null or strlen($name) < strlen($manifestPath)) and
preg_match('#.*/manifest.json$#', $name) === 1
@ -156,6 +157,6 @@ class ZippedResourcePack implements ResourcePack{
if(feof($this->fileResource)){
throw new \InvalidArgumentException("Requested a resource pack chunk with invalid start offset");
}
return fread($this->fileResource, $length);
return Utils::assumeNotFalse(fread($this->fileResource, $length), "Already checked that we're not at EOF");
}
}