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 panic on empty read from file #15

Merged
merged 1 commit into from
Dec 9, 2022
Merged

fix panic on empty read from file #15

merged 1 commit into from
Dec 9, 2022

Conversation

dadada
Copy link
Collaborator

@dadada dadada commented Dec 7, 2022

This fixes #16 a read from an empty file or from the end of a file. I'm not entirely sure under which conditions the file can be empty, but the cursor might be moved between seeking it to the beginnging of the file and reading from it. I encountered the problem only occasionally when running the hypervisor with two partitions for a while.

@dadada
Copy link
Collaborator Author

dadada commented Dec 7, 2022

@emilengler

@dadada
Copy link
Collaborator Author

dadada commented Dec 7, 2022

Sorry for all the force pushes. Should be fine now.

@dadada
Copy link
Collaborator Author

dadada commented Dec 7, 2022

This does not work, since the Vec does not have any elements.

@dadada dadada changed the title fix panic on read from empty file fix panic on empty read from file Dec 8, 2022
@wucke13 wucke13 merged commit d3d68cf into DLR-FT:main Dec 9, 2022
} else {
return Err(ErrorReturnCode::NotAvailable);
};
if let Some((port, val)) = read.get(sampling_port_id as usize - 1) {
Copy link
Member

Choose a reason for hiding this comment

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

Can sampling_port_id be zero? I see potential for an unsigned integer wrap here. If not, I would comment it at least.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The sampling_port_id is always greater than zero, since it is (incidentally) derived from the current length, after inserting an element, of the ArrayVec storing the sampling ports. https://github.com/aeronautical-informatics/apex-linux/pull/15/files#diff-d21de3347b5e6174c93c455b533568b798d139a47f7ba2564655c0731e27f889R120

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.

Panic when reading from a Sampling port destination
3 participants