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

-Wunused-result fread()'ing in parser.hpp #249

Closed
rchildre3 opened this issue Jun 26, 2024 · 1 comment
Closed

-Wunused-result fread()'ing in parser.hpp #249

rchildre3 opened this issue Jun 26, 2024 · 1 comment

Comments

@rchildre3
Copy link

Thank you so much for this great library!

after updating to v4.0.1 I am getting -Wunused-result compiler warnings on the two fread() calls in parser.hpp (in parse() and try_parse()) (using Clang 15):

.../parser.hpp:3717:5: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
    std::fread(letters.data(), sizeof(char), static_cast<std::size_t>(fsize), fp);
    ^~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../parser.hpp:3755:5: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
    std::fread(letters.data(), sizeof(char), static_cast<std::size_t>(fsize), fp);
    ^~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

These calls should probably check the return value of std::fread() to make sure the proper number of members were read in?

@ToruNiina
Copy link
Owner

ToruNiina commented Jun 26, 2024

Good catch! (I don't know why it does not have any warnings on CI)

And we need to add note that FILE* must be opened in the binary mode, to make sure that the number of characters are kept (to avoid conversion between CRLF and LF) to the docs.

Would you like to create a PullReq on this? I'll be working on it in the next weekend, so if I hear back by then I'll wait for it.

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

No branches or pull requests

2 participants