Skip to content

crc32.c triggers -Wshorten-64-to-32 with Clang #1287

Description

@bmehta001

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions