From df04a37a8ca16681676bf6421124effc1d137189 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 18 Jan 2025 20:47:06 +0900 Subject: [PATCH] [qfcc] Count terms correctly Parentheses confused the term counting because they weren't taken into account for the "neither expression can be split" check, resulting in a later segfault due to walking off the end of the array. --- tools/qfcc/source/expr_algebra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/qfcc/source/expr_algebra.c b/tools/qfcc/source/expr_algebra.c index 7c61f3530..9c123ca74 100644 --- a/tools/qfcc/source/expr_algebra.c +++ b/tools/qfcc/source/expr_algebra.c @@ -454,7 +454,7 @@ count_terms (const expr_t *expr) } auto e1 = expr->expr.e1; auto e2 = expr->expr.e2; - int terms = !is_sum (e1) + !is_sum (e2); + int terms = (!is_sum (e1) || e1->paren) + (!is_sum (e2) || e2->paren); if (!e1->paren && is_sum (e1)) { terms += count_terms (expr->expr.e1); }