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
[Windows] Fix test compilation warnings with Visual Studio #2178
Conversation
Without this change, seen warning with Visual Studio 2022 is: warning C4996: 'chmod': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _chmod. See online help for details. Debug builds have -Werror set, so fix this warning.
Add required casts and avoid unreachable code by using else-statements in preprocessor. Fixes warnings: - warning C4244: '=': conversion from '__int64' to 'int', possible loss of data - warning C4702: unreachable code Co-authored-by: Duncan Horn <dunhor@microsoft.com>
I split test code from production code for easier discussions and merges. |
@@ -932,19 +932,19 @@ DEFINE_TEST(test_read_format_rar5_symlink) | |||
assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); | |||
assertEqualString("file.txt", archive_entry_symlink(ae)); | |||
assertEqualInt(AE_SYMLINK_TYPE_FILE, archive_entry_symlink_type(ae)); | |||
assertA(0 == archive_read_data(a, NULL, archive_entry_size(ae))); | |||
assertEqualInt(0, archive_entry_size(ae)); |
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.
This test should continue to verify that archive_read_data
returns zero here. I think the best thing is to keep the line you've added and put back the previous check as a separate line: that is, verify that archive_entry_size
returns zero, and then that requesting zero bytes results in a zero byte read.
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.
Okay, I have added it again. It requires a cast to size_t though. But since we have checked that it's 0 before, this has no negative impact. Otherwise a simple cast on 32 bit systems could hide a bug if archive_entry_size is larger than SIZE_MAX. Although every other 64 bit system would notice that.
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.
One small request; otherwise this all looks great.
The test succeeds only if archive_entry_size is 0, so to avoid casting we can check exactly this condition. Fixes: warning C4244: 'function': conversion from 'la_int64_t' to 'size_t', possible loss of data
Fixes all test-related compiler warnings with Visual Studio 2022 on Windows 11.
Contains some changes from #2095.
CC: @dunhor