Fix crc32 computation when buffer is NULL

This commit is contained in:
negativeExponent
2020-02-16 20:30:08 +08:00
parent b30ea1ff7a
commit 1f5ffc3f14

View File

@@ -83,16 +83,19 @@ static const unsigned long crc_table[256] = {
static unsigned long crc32(unsigned long crc, const unsigned char *buf, unsigned int len) static unsigned long crc32(unsigned long crc, const unsigned char *buf, unsigned int len)
{ {
if (buf == 0) return 0L; const unsigned char *p;
crc = crc ^ 0xffffffffL; crc = crc ^ 0xffffffffL;
while (len >= 8) p = (const unsigned char*)buf;
{ if (p) {
DO8_CRC32(buf); while (len >= 8)
len -= 8; {
} DO8_CRC32(p);
if (len) do { len -= 8;
DO1_CRC32(buf); }
} while (--len); if (len) do {
DO1_CRC32(p);
} while (--len);
}
return crc ^ 0xffffffffL; return crc ^ 0xffffffffL;
} }