浏览代码

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

Fischer, Simon 3 年之前
父节点
当前提交
15cf3f2292
共有 1 个文件被更改,包括 2 次插入1 次删除
  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;