Skip to content

Commit c15e221

Browse files
author
bors-servo
authored
Auto merge of #164 - catdesk:issue_142, r=KiChjang
Check bounds when calling Comment::get_child (fix #142) Fixes #142.
2 parents 6ff1c1d + 449e101 commit c15e221

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/clang.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,11 @@ impl Comment {
793793
}
794794

795795
/// Get this comment's `idx`th child comment
796-
pub fn get_child(&self, idx: c_uint) -> Comment {
797-
unsafe {
798-
Comment { x: clang_Comment_getChild(self.x, idx) }
796+
pub fn get_child(&self, idx: c_uint) -> Option<Comment> {
797+
if idx >= self.num_children() {
798+
None
799+
} else {
800+
Some(Comment { x: unsafe { clang_Comment_getChild(self.x, idx) } })
799801
}
800802
}
801803

src/ir/annotations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl Annotations {
153153
}
154154

155155
for i in 0..comment.num_children() {
156-
self.parse(&comment.get_child(i), matched);
156+
self.parse(&comment.get_child(i).unwrap(), matched);
157157
}
158158
}
159159
}

0 commit comments

Comments
 (0)