diff --git a/lib/src/geneval.c b/lib/src/geneval.c index f015f5600..12e1031e7 100644 --- a/lib/src/geneval.c +++ b/lib/src/geneval.c @@ -4387,9 +4387,22 @@ static NODE *matrix_fill_func (NODE *l, NODE *r, int f, parser *p) int cols = 0, rows = node_get_int(l, p); NODE *ret = NULL; - if (!p->err) { - cols = (f == F_IMAT)? rows : node_get_int(r, p); - } + if (!p->err) { + if (f == F_IMAT) { + cols = rows; + } else if (f == F_ZEROS || f == F_ONES || f == F_MUNIF || f == F_MNORM) { + cols = 1; + /* the r node may be absent (which means one column), but if present + it should hold a scalar */ + if (!empty_or_num(r)) { + node_type_error(f, 2, NUM, r, p); + } else if (!null_or_empty(r)) { + cols = node_get_int(r, p); + } + } else { /* anything actually going into this branch? */ + cols = node_get_int(r, p); + } + } if (!p->err && !ok_matrix_dim(rows, cols, f)) { p->err = E_INVARG; @@ -15733,7 +15746,7 @@ static NODE *eval (NODE *t, parser *p) case F_MUNIF: case F_MNORM: /* matrix-creation functions */ - if (scalar_node(l) && (r == NULL || scalar_node(r))) { + if (scalar_node(l) && (null_or_empty(r) || scalar_node(r))) { /* was r == NULL */ ret = matrix_fill_func(l, r, t->t, p); } else if (!scalar_node(l)) { node_type_error(t->t, 1, NUM, l, p);