Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address C4244 warnings in MSVC build #852

Closed

Conversation

GrabYourPitchforks
Copy link
Contributor

Allows the MSVC build to compile clean when the C4244 warning code (checking for potentially lossy implicit integer narrowing casts) is enabled. I've tried to follow the same coding convention as was used in 3df8424.

An analysis our review team performed to convince ourselves of the correctness of the changes...

The change to deflate.c is legal because 'len' has an upper bound of MAX_STORED, which means it fits cleanly into a 16-bit integer. So writing out 2x 8-bit values will not result in data loss.

The change to trees.c is legal because within this loop, 'count' is intended to have an upper bound of 138, with the target assignment only executing if 'count' is bounded by 4. Neither the 'count' local in isolation nor the addition that's part of the target line is expected to result in integer overflow. But even if it did, that's a matter for a different warning code and doesn't impact the correctness of the narrowing cast being considered here.

@AraHaan
Copy link
Contributor

AraHaan commented Sep 27, 2023

Interesting, so this is affecting dotnet/runtime? I wonder how my vc17 changes affect dotnet/runtime by chance.

@GrabYourPitchforks
Copy link
Contributor Author

Interesting, so this is affecting dotnet/runtime? I wonder how my vc17 changes affect dotnet/runtime by chance.

It affects our ability to enable more C++ warnings as errors within our build. We've already made these changes locally so that we can re-enable the warning codes, but I'm sending them back upstream in case the project maintainer wants to take them. As far as I can tell there's no behavioral change.

@AraHaan
Copy link
Contributor

AraHaan commented Oct 19, 2023

Alright thanks, I was wondering if it would affect dotnet/runtime in a good way as well.

@madler
Copy link
Owner

madler commented Jan 23, 2024

Incorporated.

@madler madler closed this Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants