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 a crash when opening an empty file. #919

Merged
merged 2 commits into from Feb 3, 2021

Conversation

ruevs
Copy link
Member

@ruevs ruevs commented Feb 1, 2021

Fixes: #918

The problem was that here:

ClearExisting();

we cleared all groups. Then we tried to read an empty file and therefore this while exited immediately:
while(fgets(line, (int)sizeof(line), fh)) {

and we came to here:
if(fileLoadError) {

where there was no fileLoadError and thus we were left with no groups, and so this assert failed:
"Group order can't be empty since we will activate the last group.");

since is is not allowed to have no groups :-)

Including de_DE and ru_RU strings.
@phkahler
Copy link
Member

phkahler commented Feb 1, 2021

I'd prefer "The file is empty." But it's OK either way.

@ruevs
Copy link
Member Author

ruevs commented Feb 2, 2021

You mean remove "it may be corrupt"?
My logic was that a normal user should normally not have a zero length slvs file, so for them " the file is empty" may be an unpleasant surprise. Not that telling them it may be corrupt will help :-)

@rpavlik
Copy link
Contributor

rpavlik commented Feb 3, 2021

I'm not sure when this message would actually appear - just when e.g. the user has a complete 0 byte slvs file? As such I have no opinion on the strings wording.

That said, the code itself looks reasonable.

@phkahler phkahler merged commit 02aa9ea into solvespace:master Feb 3, 2021
@ruevs
Copy link
Member Author

ruevs commented Feb 4, 2021

I'm not sure when this message would actually appear - just when e.g. the user has a complete 0 byte slvs file?

Yes, only on a 0 byte file.
Only then the first fgets would return 0 (a null pointer).

"If the end-of-file is encountered while attempting to read a character, the eof indicator is set (feof). If this happens before any characters could be read, the pointer returned is a null pointer (and the contents of str remain unchanged)."

@ruevs ruevs deleted the EmptyFileCrash branch February 4, 2021 06:34
@ruevs ruevs mentioned this pull request Feb 4, 2021
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.

Opening and Empty .slvs File Causes a Crash (Was: "Crash after autosave-restore dialog wth file from v2.3")
3 participants