From 16c2b69a496b7b69c98875dec348b8a8a16b4fa9 Mon Sep 17 00:00:00 2001 From: grailguo Date: Thu, 4 Jun 2026 03:44:26 -0400 Subject: [PATCH] Fix size calculation in new_expr function --- tinyexpr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tinyexpr.c b/tinyexpr.c index 176e8d0..ebf8dfe 100755 --- a/tinyexpr.c +++ b/tinyexpr.c @@ -87,7 +87,7 @@ typedef struct state { static te_expr *new_expr(const int type, const te_expr *parameters[]) { const int arity = ARITY(type); const int psize = sizeof(void*) * arity; - const int size = (sizeof(te_expr) - sizeof(void*)) + psize + (IS_CLOSURE(type) ? sizeof(void*) : 0); + const int size = sizeof(te_expr) + sizeof(void*) * (arity > 0 ? arity - 1 : 0) + (IS_CLOSURE(type) ? sizeof(void*) : 0); te_expr *ret = malloc(size); CHECK_NULL(ret);