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

Core/Common/VideoCommon: Fix some weird (!eof) logic. #13180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jordan-woyak
Copy link
Member

Logic of the form, while (!eof), is almost always "wrong".

The success of the actual read needs to be tested, which may or may not trigger eof.

The three pieces of code I found with while (!eof) did also test that the read was successful, so the behavior was correct, but the eof checks were still unnecessary and made the loops awkward.

Comment on lines -258 to -261
if (in.eof())
return true;
else
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should return in.eof() at the end of the function instead of just true in case there was a read error (and get rid of the redundant close).

Copy link
Member Author

@jordan-woyak jordan-woyak Nov 12, 2024

Choose a reason for hiding this comment

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

I don't think so. So long as the file can be opened (which is checked by if (in.fail()) above), while (std::getline(in, line_str)) will process lines until no more lines can be read, and then we are done, and it was successful. eof is not relevant. That's the point of this PR. ;) but, yeah, the close is superfluous and could be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well... technically, the read could fail mid-file if you have a disk error, or your USB device gets disconnected, or something like that. In that case you'd want to return false and not true, since you don't want the caller to proceed with half a file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants