-
Notifications
You must be signed in to change notification settings - Fork 634
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
Conversation
@@ -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)()) |
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.
I think it should be std::uint64_t
instead of unsigned long
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.
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.
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.
But if the input argument type to seek is std::uint64_t
why should we care?
The warning is quite annoying with -Wall
flag.
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.
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())) |
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 looks right now, thanks
This fixes a C4388 warning when compiling with MSVC.