From 54c3f5190c705e4981099ea920e388d989d3fcfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Fri, 4 Feb 2022 19:21:16 +0000 Subject: [PATCH] glsl-in: Fix panic when culling nested block (#1714) Under certatin circumstances the parser would panic because of culling using an index out of bound, for example take the following code: ```glsl { x = 1; // Index 0 on nested block discard; // Index 1 on nested block } // Index 0 on block ``` The parser seeing this would attempt to cull the block using the start index of 1 which would be out of bound and panic. Now instead the nested block properly does it's internal culling and the outer block culls everything after the nested block only. --- src/front/glsl/parser/functions.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/front/glsl/parser/functions.rs b/src/front/glsl/parser/functions.rs index 6483db0521..f684ada6c7 100644 --- a/src/front/glsl/parser/functions.rs +++ b/src/front/glsl/parser/functions.rs @@ -486,12 +486,21 @@ impl<'source> ParsingContext<'source> { let mut block = Block::new(); ctx.push_scope(); - let meta = - self.parse_compound_statement(meta, parser, ctx, &mut block, terminator)?; + let mut block_terminator = None; + let meta = self.parse_compound_statement( + meta, + parser, + ctx, + &mut block, + &mut block_terminator, + )?; ctx.remove_current_scope(); body.push(Statement::Block(block), meta); + if block_terminator.is_some() { + terminator.get_or_insert(body.len()); + } meta }