Fix crc32 computation when buffer is NULL
This commit is contained in:
23
src/crc32.c
23
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)
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user