in reply to computing CRC32 in Perl and C
After comparing your code to String::CRC32's, I found that
return lCrc;
should be
return lCrc ^ *mMask;
Furthermore, you're comparing the checksum of different things.
sizeof(s)
should be
strlen(s) (or sizeof(s)-1)
You assume int is no less than 32 bits long. That's not guaranteed.
unsigned int lCrc
unsigned int mMask
unsigned int lPolynomial
should be
unsigned long lCrc
unsigned long mMask
unsigned long lPolynomial
You assume int is no more than 32 bits long. That's not guaranteed.
(lCrc >> 8)
should be
((lCrc >> 8) & 0x00FFFFFF)
Finally, crc accepts a pointer to mMask when it could simply accept mMask directly. This isn't a bug, so much as needless complication.
Tested.
|
|---|