From 449e10110cc8e9aa951654cb2127cf71c95aca68 Mon Sep 17 00:00:00 2001 From: catdesk Date: Sat, 29 Oct 2016 16:53:04 +0200 Subject: [PATCH] Check bounds when calling Comment::get_child (fix #142) --- src/clang.rs | 8 +++++--- src/ir/annotations.rs | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index c0934055cc..ae4a3f44e0 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 { + 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 f0d9715e5e..d276608f13 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); } } }