Skip to content

forbid unsafe #357

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

Closed

Conversation

tamasblummer
Copy link
Contributor

Please consider this. I do not think performance hit justifies unsafe language use.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Looks good, mod the one comment

let mut res: Vec<msgs::OnionHopData> = Vec::with_capacity(route.hops.len());
internal_traits::test_no_dealloc::<msgs::OnionHopData>(None);
unsafe { res.set_len(route.hops.len()); }
let mut res: Vec<msgs::OnionHopData> = vec![msgs::OnionHopData::default(); route.hops.len()];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would prefer to just insert(0, ...) at each loop iteration to make things even cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do not know how to insert if not initialized. vec capacity != len

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if vec length is not 20*65 shift will fail

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oops, I missed this, point was we don't shift on this vec, only on a later version of it, this one is always route.hops.len() in len at the end.

@TheBlueMatt TheBlueMatt mentioned this pull request Jul 24, 2019
@TheBlueMatt
Copy link
Collaborator

Taken as #358.

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.

2 participants