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);