diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-10-29 22:14:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-29 22:14:42 -0500 |
commit | c15e221be7f9c24681c024932fca66a008e5d348 (patch) | |
tree | c8d21aba583d6f7837053a4471cfc7f68b57a891 | |
parent | 6ff1c1d90efc1da0529a3d4ef9e457eee97f768d (diff) | |
parent | 449e10110cc8e9aa951654cb2127cf71c95aca68 (diff) |
Auto merge of #164 - catdesk:issue_142, r=KiChjang
Check bounds when calling Comment::get_child (fix #142)
Fixes #142.
-rwxr-xr-x | src/clang.rs | 8 | ||||
-rw-r--r-- | src/ir/annotations.rs | 2 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/clang.rs b/src/clang.rs index c0934055..ae4a3f44 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -793,9 +793,11 @@ impl Comment { } /// Get this comment's `idx`th child comment - pub fn get_child(&self, idx: c_uint) -> Comment { - unsafe { - Comment { x: clang_Comment_getChild(self.x, idx) } + pub fn get_child(&self, idx: c_uint) -> Option<Comment> { + if idx >= self.num_children() { + None + } else { + Some(Comment { x: unsafe { clang_Comment_getChild(self.x, idx) } }) } } diff --git a/src/ir/annotations.rs b/src/ir/annotations.rs index f0d9715e..d276608f 100644 --- a/src/ir/annotations.rs +++ b/src/ir/annotations.rs @@ -153,7 +153,7 @@ impl Annotations { } for i in 0..comment.num_children() { - self.parse(&comment.get_child(i), matched); + self.parse(&comment.get_child(i).unwrap(), matched); } } } |