diff --git a/pd/extra/expr~/vexp.c b/pd/extra/expr~/vexp.c
index f1cd483aa1f2efa54a1eb7746288518ba58723c7..45380ff97798b62a2de8689e861757123d327e8f 100644
--- a/pd/extra/expr~/vexp.c
+++ b/pd/extra/expr~/vexp.c
@@ -265,6 +265,11 @@ expr_donew(struct expr *expr, int ac, t_atom *av)
                   (struct ex_ex *)fts_malloc(max_node * sizeof (struct ex_ex));
                 expr->exp_nexpr++;
                 ret = ex_match(list, (long)0);
+                if (expr->exp_nexpr > MAX_VARS) // we cannot exceed the number of max vars (arbitrarily set to 9 in vexp.h)
+                {
+                        post_error((fts_object_t *) expr, "expr: too many variables (maximum %d allowed)", MAX_VARS);
+                        goto error;   
+                }
                 if (!ret)               /* syntax error */
                         goto error;
                 ret = ex_parse(expr,