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 key up/down #16

Merged
merged 2 commits into from
Mar 20, 2023
Merged

fix: panic on key up/down #16

merged 2 commits into from
Mar 20, 2023

Conversation

dzfrias
Copy link
Contributor

@dzfrias dzfrias commented Mar 19, 2023

Fixes #15

@EdJoPaTo
Copy link
Owner

While this fixes the issue by preventing it in the first place it's not solving the underlying issue: using slice[index] which can panic. Personally I would go for fixing it by moving over to slice.get(index) which returns an Option instead. Then this option can be handled cleanly. This sounds cleaner to me.

-let new_identifier = visible[new_index].identifier.clone();
+let new_identifier = visible
+    .get(new_index)
+    .map(|o| o.identifier.clone())
+    .unwrap_or_default();

What do you think?

@dzfrias
Copy link
Contributor Author

dzfrias commented Mar 20, 2023

That sounds good; I can replace it with that!

@EdJoPaTo EdJoPaTo changed the title Fix #15 fix: panic on key up/down Mar 20, 2023
Copy link
Owner

@EdJoPaTo EdJoPaTo left a comment

Choose a reason for hiding this comment

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

Thank you for your time proving the PR and your report about this issue!

@EdJoPaTo EdJoPaTo merged commit 61bc6da into EdJoPaTo:main Mar 20, 2023
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.

Index out of bounds with key_down and key_up
2 participants