Skip to content

Commit 4692441

Browse files
committed
Bail if we find no closing parenthesis
1 parent e47ab87 commit 4692441

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/ir/var.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,21 @@ fn handle_function_macro(
139139
tokens: &[clang::ClangToken],
140140
callbacks: &dyn crate::callbacks::ParseCallbacks,
141141
) -> Result<(), ParseError> {
142+
let mut spelled =
143+
tokens.into_iter().map(clang::ClangToken::spelling);
144+
let boundary = spelled
145+
.clone() // clone the iterator to avoid consuming elements
146+
.position(|s| s == b")");
147+
142148
// cexpr explicitly does not handle function-like macros, except for a
143149
// degenerate case in which it behaves in a non-conformant way. We prevent
144150
// cexpr from ever seeing function-like macros by checking for a parenthesis
145151
// token immediately adjacent to (that is, abutting) the first token in the
146152
// macro definition.
147-
match tokens.get(0..2) {
148-
Some([first, second])
153+
match (tokens.get(0..2), boundary) {
154+
(Some([first, second]), Some(boundary))
149155
if first.is_abutting(&second) && second.spelling() == b"(" =>
150156
{
151-
let mut spelled =
152-
tokens.into_iter().map(clang::ClangToken::spelling);
153-
let boundary = spelled
154-
.clone() // clone the iterator to avoid consuming elements
155-
.position(|s| s == b")")
156-
.unwrap_or(joined.len());
157-
158157
// Add 1, to convert index to length.
159158
let left = spelled.by_ref().take(boundary + 1);
160159
let left = left.collect::<Vec<_>>().concat();

0 commit comments

Comments
 (0)