backport some cleanup that I clearly missed wasn't there already to do with ZWAD lump loading

This commit is contained in:
Monster Iestyn 2018-11-29 14:16:02 +00:00
parent e158206e55
commit 305ad4f73e

View file

@ -1215,30 +1215,31 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
I_Error("wad %d, lump %d: cannot read compressed data", wad, lump); I_Error("wad %d, lump %d: cannot read compressed data", wad, lump);
retval = lzf_decompress(rawData, l->disksize, decData, l->size); retval = lzf_decompress(rawData, l->disksize, decData, l->size);
#ifndef AVOID_ERRNO #ifndef AVOID_ERRNO
if (retval == 0 && errno == E2BIG) // errno is a global var set by the lzf functions when something goes wrong. if (retval == 0) // If this was returned, check if errno was set
{ {
I_Error("wad %d, lump %d: compressed data too big (bigger than %s)", wad, lump, sizeu1(l->size)); // errno is a global var set by the lzf functions when something goes wrong.
if (errno == E2BIG)
I_Error("wad %d, lump %d: compressed data too big (bigger than %s)", wad, lump, sizeu1(l->size));
else if (errno == EINVAL)
I_Error("wad %d, lump %d: invalid compressed data", wad, lump);
} }
else if (retval == 0 && errno == EINVAL) // Otherwise, fall back on below error (if zero was actually the correct size then ???)
I_Error("wad %d, lump %d: invalid compressed data", wad, lump);
else
#endif #endif
if (retval != l->size) if (retval != l->size)
{ {
I_Error("wad %d, lump %d: decompressed to wrong number of bytes (expected %s, got %s)", wad, lump, sizeu1(l->size), sizeu2(retval)); I_Error("wad %d, lump %d: decompressed to wrong number of bytes (expected %s, got %s)", wad, lump, sizeu1(l->size), sizeu2(retval));
} }
#else
(void)wad;
(void)lump;
//I_Error("ZWAD files not supported on this platform.");
return NULL;
#endif
if (!decData) // Did we get no data at all? if (!decData) // Did we get no data at all?
return 0; return 0;
M_Memcpy(dest, decData + offset, size); M_Memcpy(dest, decData + offset, size);
Z_Free(rawData); Z_Free(rawData);
Z_Free(decData); Z_Free(decData);
return size; return size;
#else
//I_Error("ZWAD files not supported on this platform.");
return 0;
#endif
} }
#ifdef HAVE_ZLIB #ifdef HAVE_ZLIB
case CM_DEFLATE: // Is it compressed via DEFLATE? Very common in ZIPs/PK3s, also what most doom-related editors support. case CM_DEFLATE: // Is it compressed via DEFLATE? Very common in ZIPs/PK3s, also what most doom-related editors support.