Building crc32.c with Clang on a 64-bit Unix target fails when -Wshorten-64-to-32 is treated as an error:
crc32.c:689:20: error: implicit conversion loses integer precision: 'uLong' (aka 'unsigned long') to 'z_crc_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
689 | crc0 = crc;
| ~ ^~~
Reproduction on the current develop branch:
clang -c crc32.c -I. -Wshorten-64-to-32 -Werror
This also affects zlib 1.3.2. The conversion is safe because crc is masked with 0xffffffff before this assignment, but Clang cannot infer that for the implicit narrowing conversion.
An explicit (z_crc_t) cast at the assignment removes the warning and documents the intended narrowing.
Building
crc32.cwith Clang on a 64-bit Unix target fails when-Wshorten-64-to-32is treated as an error:Reproduction on the current
developbranch:This also affects zlib 1.3.2. The conversion is safe because
crcis masked with0xffffffffbefore this assignment, but Clang cannot infer that for the implicit narrowing conversion.An explicit
(z_crc_t)cast at the assignment removes the warning and documents the intended narrowing.