-
-
Notifications
You must be signed in to change notification settings - Fork 308
Fix casting warning/error in test_compress_bound.cc #1814
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
Conversation
Fixes the following error when building with msvc compiler ``` test_compress_bound.cc D:\zlib-ng\test\test_compress_bound.cc(41,50): error C2220: the following warning is treated as an error D:\zlib-ng\test\test_compress_bound.cc(41,50): warning C4267: 'argument': conversion from 'size_t' to 'unsigned long', possible loss of data D:\zlib-ng\test\test_compress_bound.cc(43,68): warning C4267: 'argument': conversion from 'size_t' to 'unsigned long', possible loss of data ```
WalkthroughThe changes in this pull request involve modifying the type of a loop variable within the Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
test/test_compress_bound.cc (1)
37-37: LGTM! The change fixes the MSVC warnings, though it might be overengineered.The switch to
z_uintmax_tsuccessfully addresses the MSVC compiler warnings about potential data loss in size_t to unsigned long conversions. While this solution is more than sufficient for the current MAX_LENGTH of 32, it provides good forward compatibility if the test range increases in the future.A simpler alternative, if you prefer, could be to just cast the values explicitly:
- for (z_uintmax_t i = 0; i < MAX_LENGTH; i++) { - z_uintmax_t dest_len = sizeof(dest); + for (z_size_t i = 0; i < MAX_LENGTH; i++) { + z_size_t dest_len = sizeof(dest); + unsigned long dest_len_ul = (unsigned long)dest_len; // Explicit castHowever, the current solution is perfectly fine and more future-proof, so this is just a stylistic suggestion.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #1814 +/- ##
===========================================
- Coverage 32.18% 32.14% -0.04%
===========================================
Files 67 67
Lines 5752 5752
Branches 1237 1237
===========================================
- Hits 1851 1849 -2
- Misses 3644 3645 +1
- Partials 257 258 +1 ☔ View full report in Codecov by Sentry. |
Dead2
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes the following error when building with msvc compiler
Summary by CodeRabbit
This change enhances the reliability of the compression output verification process.