Jelajahi Sumber

add somewhat explicit uint8_t cast to crc computation to avoid errors caused by signedness mistakes

Fischer, Simon 3 tahun lalu
induk
melakukan
15cf3f2292
1 mengubah file dengan 2 tambahan dan 1 penghapusan
  1. 2 1
      src/shellmatta_crc.c

+ 2 - 1
src/shellmatta_crc.c

@@ -125,7 +125,8 @@ uint32_t crc32Fast(char* data, uint16_t size, uint32_t* lookupTable)
 
     for (i = 0; i < size; i++)
     {
-        crcTemp = lookupTable[data[i] ^ (crcTemp & 0xff)] ^ (crcTemp >> 8);
+        uint8_t index = data[i] ^ (crcTemp & 0xff);
+        crcTemp = lookupTable[index] ^ (crcTemp >> 8);
     }
 
     return ~crcTemp;