crc32.c triggers -Wshorten-64-to-32 with Clang
Author: bmehta001Created Jul 28, 2026Updated Jul 28, 2026
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 -WerrorThis 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.
Source: madler/zlib