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

Fix signed/unsigned mismatch in file_stdio::seek #1687

Closed
wants to merge 1 commit into from
Closed

Fix signed/unsigned mismatch in file_stdio::seek #1687

wants to merge 1 commit into from

Conversation

achartier
Copy link
Contributor

This fixes a C4388 warning when compiling with MSVC.

@@ -241,7 +241,7 @@ seek(std::uint64_t offset, error_code& ec)
ec = make_error_code(errc::bad_file_descriptor);
return;
}
if(offset > (std::numeric_limits<long>::max)())
if(offset > (std::numeric_limits<unsigned long>::max)())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be std::uint64_t instead of unsigned long

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I don't think so. stdio (e.g. FILE*) only supports 32 bit offsets: https://en.cppreference.com/w/cpp/io/c/fseek
If you want support for large files you have to use one of the platform-specific implementations.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if the input argument type to seek is std::uint64_t why should we care?

The warning is quite annoying with -Wall flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misunderstood that check earlier. Updated the change to cast the std::numeric_limits value into a std::uint64_t instead.

@@ -241,7 +241,7 @@ seek(std::uint64_t offset, error_code& ec)
ec = make_error_code(errc::bad_file_descriptor);
return;
}
if(offset > (std::numeric_limits<long>::max)())
if(offset > static_cast<std::uint64_t>(std::numeric_limits<long>::max()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks right now, thanks

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.

3 participants