From 1f5ffc3f147b8d0083eac601f8472bc76c5f43eb Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Sun, 16 Feb 2020 20:30:08 +0800 Subject: [PATCH] Fix crc32 computation when buffer is NULL --- src/crc32.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/crc32.c b/src/crc32.c index 6bee3cd..2daa51d 100644 --- a/src/crc32.c +++ b/src/crc32.c @@ -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; }