Some zero init, add a null check in TextureReplacer. See #15730

This commit is contained in:
Henrik Rydgård 2022-07-26 23:48:39 +02:00
parent a92e764c65
commit 18f828d74b
2 changed files with 7 additions and 5 deletions

View File

@ -231,7 +231,7 @@ bool CISOFileBlockDevice::ReadBlock(int blockNumber, u8 *outPtr, bool uncached)
const u32 idx = index[frameNumber];
const u32 indexPos = idx & 0x7FFFFFFF;
const u32 nextIndexPos = index[frameNumber + 1] & 0x7FFFFFFF;
z_stream z;
z_stream z{};
const u64 compressedReadPos = (u64)indexPos << indexShift;
const u64 compressedReadEnd = (u64)nextIndexPos << indexShift;
@ -311,10 +311,7 @@ bool CISOFileBlockDevice::ReadBlocks(u32 minBlock, int count, u8 *outPtr) {
const u32 afterLastIndexPos = index[lastFrameNumber + 1] & 0x7FFFFFFF;
const u64 totalReadEnd = (u64)afterLastIndexPos << indexShift;
z_stream z;
z.zalloc = Z_NULL;
z.zfree = Z_NULL;
z.opaque = Z_NULL;
z_stream z{};
if (inflateInit2(&z, -15) != Z_OK) {
ERROR_LOG(LOADER, "Unable to initialize inflate: %s\n", (z.msg) ? z.msg : "?");
return false;

View File

@ -456,6 +456,11 @@ bool TextureReplacer::PopulateLevel(ReplacedTextureLevel &level) {
bool good = false;
FILE *fp = File::OpenCFile(level.file, "rb");
if (!fp) {
ERROR_LOG(G3D, "Error opening replacement texture file '%s'", level.file.c_str());
return false;
}
auto imageType = Identify(fp);
if (imageType == ReplacedImageType::ZIM) {
fseek(fp, 4, SEEK_SET);