[qfcc] Check switch test expression early

Avoids a segfault when the test expression has errors.
This commit is contained in:
Bill Currie 2021-12-27 00:47:35 +09:00
parent 3059aa7979
commit 95991e0d77

View file

@ -395,6 +395,10 @@ struct expr_s *
switch_expr (switch_block_t *switch_block, expr_t *break_label, switch_expr (switch_block_t *switch_block, expr_t *break_label,
expr_t *statements) expr_t *statements)
{ {
if (switch_block->test->type == ex_error) {
return switch_block->test;
}
case_label_t **labels, **l; case_label_t **labels, **l;
case_label_t _default_label; case_label_t _default_label;
case_label_t *default_label = &_default_label; case_label_t *default_label = &_default_label;
@ -406,10 +410,6 @@ switch_expr (switch_block_t *switch_block, expr_t *break_label,
int saved_line = pr.source_line; int saved_line = pr.source_line;
string_t saved_file = pr.source_file; string_t saved_file = pr.source_file;
if (switch_block->test->type == ex_error) {
return switch_block->test;
}
pr.source_line = sw_val->line = switch_block->test->line; pr.source_line = sw_val->line = switch_block->test->line;
pr.source_file = sw_val->file = switch_block->test->file; pr.source_file = sw_val->file = switch_block->test->file;