EmbeddedRPC / erpc

Embedded RPC
https://github.com/EmbeddedRPC/erpc/wiki
BSD 3-Clause "New" or "Revised" License
782 stars 214 forks source link

crc16 is using internal crc with 32 bit size #348

Open amgross opened 1 year ago

amgross commented 1 year ago

https://github.com/EmbeddedRPC/erpc/blob/60a3cc1f84351cc3bf1af719d662e979a8f19b1c/erpc_c/infra/erpc_crc16.cpp#L32-L38 Maybe I am missing something. Why can't the variables crc, temp, andValue, xorValuebe uint32_t and bytebe uint8_t ? It makes things cleaner and I don't see it effects the algorithm

Hadatko commented 1 year ago

Hi @amgross , so only change you are suggesting is change byte to uint8_t correct? I am not against it but we need be carefull. I think "byte<<8" can do undefined behavior. Compiler can throw away one byte. So we need recast it then ((uint16_t)(byte)) << 8

amgross commented 1 year ago

Oops, I wrote wrong, I mean: Why can't the variables crc, temp, andValue, xorValuebe uint16_t

amgross commented 1 year ago

About byte<<8, Please see https://stackoverflow.com/questions/69143163/c-uses-different-data-type-for-arithmetic-in-the-middle-of-an-expression . byte<<8 is equivalent to ((unsigned int)byte)<<8