Skip to content

Commit

Permalink
Fixing undefined behavior in lib CRC (#2269)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStarch authored Sep 6, 2023
1 parent 206f74b commit 87fa458
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Utils/Hash/libcrc/lib_crc.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ unsigned short update_crc_16( unsigned short crc, char c ) {
if ( ! crc_tab16_init ) init_crc16_tab();

tmp = crc ^ short_c;
crc = (crc >> 8) ^ crc_tab16[ tmp & 0xff ];
// Note: when masking by 0xff, range is limited to unsigned char
// which fits within unsigned int.
crc = (crc >> 8) ^ crc_tab16[ (unsigned int)(tmp & 0xff) ];

return crc;

Expand Down

0 comments on commit 87fa458

Please sign in to comment.