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

[Windows] Fix test compilation warnings with Visual Studio #2178

Merged
merged 3 commits into from May 12, 2024

Conversation

stoeckmann
Copy link
Contributor

Fixes all test-related compiler warnings with Visual Studio 2022 on Windows 11.

Contains some changes from #2095.

CC: @dunhor

stoeckmann and others added 2 commits May 10, 2024 20:21
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>
@stoeckmann stoeckmann changed the title [Windows] Fix test compilation with Visual Studio [Windows] Fix test compilation warnings with Visual Studio May 10, 2024
@stoeckmann
Copy link
Contributor Author

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));
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@kientzle kientzle left a 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
@kientzle kientzle merged commit 3085a3e into libarchive:master May 12, 2024
20 checks passed
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.

None yet

2 participants