Skip to content

Check bounds when calling Comment::get_child (fix #142) #164

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

Merged
merged 1 commit into from
Oct 30, 2016

Conversation

catdesk
Copy link
Contributor

@catdesk catdesk commented Oct 29, 2016

Fixes #142.

@highfive
Copy link

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

} else {
unsafe {
Some(Comment { x: clang_Comment_getChild(self.x, idx) })
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm very new to rust, but my understanding is that unsafe code should be as limited as possible.
I see quite a few different practices in this file, but would it be sensible/work to have something like this?

Some( unsafe { Comment { x: clang_Comment_getChild(self.x, idx) } } )
Or
Some( Comment { x: unsafe { clang_Comment_getChild(self.x, idx) } } )

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, ideally, your later example is preferable. In this case it's not a big deal though, since there's no extra potentially unsafe stuff going on in that block.

Copy link
Contributor

@emilio emilio 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 to me, just one nit. Also, feel free to address @jeanphilippeD comment if you wish.

Thanks!

@@ -153,7 +153,8 @@ impl Annotations {
}

for i in 0..comment.num_children() {
self.parse(&comment.get_child(i), matched);
let child = &comment.get_child(i).expect("index higher than number of children");
Copy link
Contributor

Choose a reason for hiding this comment

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

Use unwrap, please, we can be sure we're inside the bounds.

@KiChjang
Copy link
Member

Squash your commits, please.

@KiChjang
Copy link
Member

Nevermind, I've squashed them for you.

@bors-servo r+

@bors-servo
Copy link

📌 Commit 449e101 has been approved by KiChjang

@bors-servo
Copy link

⌛ Testing commit 449e101 with merge c15e221...

bors-servo pushed a commit that referenced this pull request Oct 30, 2016
Check bounds when calling Comment::get_child (fix #142)

Fixes #142.
@bors-servo
Copy link

☀️ Test successful - status-travis

@bors-servo bors-servo merged commit 449e101 into rust-lang:master Oct 30, 2016
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.

6 participants