Skip to content

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

Closed
achartier wants to merge 1 commit intoboostorg:developfrom
achartier:develop
Closed

Fix signed/unsigned mismatch in file_stdio::seek#1687
achartier wants to merge 1 commit intoboostorg:developfrom
achartier:develop

Conversation

@achartier
Copy link
Copy Markdown
Contributor

This fixes a C4388 warning when compiling with MSVC.

return;
}
if(offset > (std::numeric_limits<long>::max)())
if(offset > (std::numeric_limits<unsigned long>::max)())
Copy link
Copy Markdown

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
Copy Markdown
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.

Copy link
Copy Markdown

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
Copy Markdown
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.

return;
}
if(offset > (std::numeric_limits<long>::max)())
if(offset > static_cast<std::uint64_t>(std::numeric_limits<long>::max()))
Copy link
Copy Markdown
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