Skip to content

Commit 287866e

Browse files
committed
Added checks for template specialization and out of bounds in template_arg_value
1 parent f498903 commit 287866e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/clang.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,26 @@ impl Cursor {
457457
/// Given that this cursor's referent is a template specialization, and that
458458
/// the `i`th template argument is an integral, get the `i`th template
459459
/// argument value.
460-
pub fn template_arg_value(&self, i: c_int) -> c_longlong {
461-
unsafe { clang_Cursor_getTemplateArgumentValue(self.x, i as c_uint) }
460+
pub fn template_arg_value(&self, i: c_int) -> Option<c_longlong> {
461+
let within_bounds = match self.num_template_args() {
462+
Some(num_args) => {
463+
if i > 0 && i < (num_args as i32) {
464+
true
465+
}
466+
else {
467+
false
468+
}
469+
},
470+
None => false
471+
};
472+
match within_bounds {
473+
true => {
474+
unsafe {
475+
Some(clang_Cursor_getTemplateArgumentValue(self.x, i as c_uint))
476+
}
477+
},
478+
false => None
479+
}
462480
}
463481
}
464482

0 commit comments

Comments
 (0)