From 95de6fee1462061d2a3faf57c0e361b82bbde07b Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Mon, 8 Jun 2026 19:02:36 -0700 Subject: [PATCH] add an assertion on index count when generating clear OpenCode claims the calculation of `ic` can underflow, leading to generation of an infinite loop. This is a false positive, so lets try to make that more obvious to static analysis tools. Reported-by: OpenCode 1.16.2 --- rumur/src/generate-stmt.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rumur/src/generate-stmt.cc b/rumur/src/generate-stmt.cc index ccb6c43a..b4816f05 100644 --- a/rumur/src/generate-stmt.cc +++ b/rumur/src/generate-stmt.cc @@ -32,7 +32,9 @@ static void clear(std::ostream &out, const TypeExpr &t, if (auto a = dynamic_cast(type.get())) { // The number of elements in this array as a C code string - mpz_class ic = a->index_type->count() - 1; + const mpz_class ic_with_undefined = a->index_type->count(); + assert(ic_with_undefined > 0); + const mpz_class ic = ic_with_undefined - 1; const std::string ub = "((size_t)" + ic.get_str() + "ull)"; // The bit size of each array element as a C code string