From 49a56b22b572b1167098e5f96a84e30cdc64f38c Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 4 Dec 2009 15:49:34 +0100 Subject: Fixed calculating CRC32 on 64bit platforms When compiling on a 64bit machine we should make sure that we won't overflow the 32bit CRC value because of casting signed int to unsigned long. Reviewed-by: Thiago --- config.tests/mac/crc/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.tests/mac/crc/main.cpp b/config.tests/mac/crc/main.cpp index 894f88b..700a4cd 100644 --- a/config.tests/mac/crc/main.cpp +++ b/config.tests/mac/crc/main.cpp @@ -71,7 +71,7 @@ private: for(int iCodes = 0; iCodes <= 0xFF; iCodes++) { ulTable[iCodes] = Reflect(iCodes, 8) << 24; for(int iPos = 0; iPos < 8; iPos++) { - ulTable[iCodes] = (ulTable[iCodes] << 1) + ulTable[iCodes] = ((ulTable[iCodes] << 1) & 0xffffffff) ^ ((ulTable[iCodes] & (1 << 31)) ? ulPolynomial : 0); } @@ -84,7 +84,7 @@ private: // Swap bit 0 for bit 7, bit 1 For bit 6, etc.... for(int iPos = 1; iPos < (cChar + 1); iPos++) { if(ulReflect & 1) { - ulValue |= (1 << (cChar - iPos)); + ulValue |= (1ul << (cChar - iPos)); } ulReflect >>= 1; } -- cgit v0.12