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)
{
if (buf == 0) return 0L;
crc = crc ^ 0xffffffffL;
while (len >= 8)
{
DO8_CRC32(buf);
len -= 8;
}
if (len) do {
DO1_CRC32(buf);
} while (--len);
const unsigned char *p;
crc = crc ^ 0xffffffffL;
p = (const unsigned char*)buf;
if (p) {
while (len >= 8)
{
DO8_CRC32(p);
len -= 8;
}
if (len) do {
DO1_CRC32(p);
} while (--len);
}
return crc ^ 0xffffffffL;
}