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

Allow an empty input file to be parsed correctly #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

myclevorname
Copy link

Yes, it uses a goto statement. Even though goto statements are considered harmful, I think it is okay in this situation. This fixes #78.

Yes, it uses a goto statement. Even though goto statements are
considered harmful, I think it is okay in this situation.
buffer[0] = '\n';
goto finished_reading;
}

rewind (file);


// If there is a UTF-8 endian marker at the beginning of the file, skip it.
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the implementation of this is the issue, I think the problem can be fixed more easily by changing this only.

Something like..

unsigned char file_head[3];
read_size = fread(file_head, 1, 3, file);
if (read_size == 3 && memcmp(file_head, utf8_endian_mark, sizeof(file_head)) == 0) {
    // Skip UTF-8 BOM
    size -= sizeof(file_head);
} else {
    // Read data needs to be retained
    rewind(file);
}

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, I will incorporate that into a new commit.

@tari
Copy link
Contributor

tari commented Jun 9, 2024

I'd also recommend adding a test for this, but that might not be easy to do since our tests are set up to have metadata in the input file.

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.

"Couldn't open input file" on input file of size 0
2 participants