Check using memcmp()

This commit is contained in:
Steel Titanium 2019-03-03 22:43:21 -05:00
parent 3d5d02fc15
commit 15323328c5

View file

@ -1183,14 +1183,10 @@ static void ErrorIfPNG(void *d, size_t s, char *f, char *l)
if (s < 67) // http://garethrees.org/2007/11/14/pngcrush/ if (s < 67) // http://garethrees.org/2007/11/14/pngcrush/
return; return;
#define sigcheck ((UINT8 *)d) #define sigcheck ((UINT8 *)d)
if (sigcheck[0] == 0x89 // Check for PNG file signature using memcmp
&& sigcheck[1] == 0x50 // As it may be faster on CPUs with slow unaligned memory access
&& sigcheck[2] == 0x4e // Ref: http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html#R.PNG-file-signature
&& sigcheck[3] == 0x47 if (memcmp(&sigcheck[0], "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a", 8) == 0)
&& sigcheck[4] == 0x0d
&& sigcheck[5] == 0x0a
&& sigcheck[6] == 0x1a
&& sigcheck[7] == 0x0a)
{ {
I_Error("W_Wad: Lump \"%s\" in file \"%s\" is a .PNG - please convert to either Doom or Flat (raw) image format.", l, f); I_Error("W_Wad: Lump \"%s\" in file \"%s\" is a .PNG - please convert to either Doom or Flat (raw) image format.", l, f);
} }