From ae3d171d915dffebf8c22bc2e4cda8983cad8103 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Mon, 21 Mar 2022 16:53:37 +0100 Subject: [PATCH] Prevent a segfault when the parameter to command 'repeat' is given, but cannot be evaluetd to a number. --- src/frontend/control.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/frontend/control.c b/src/frontend/control.c index 4f7f1f460..7f5b05bd2 100644 --- a/src/frontend/control.c +++ b/src/frontend/control.c @@ -716,13 +716,18 @@ cp_evloop(char *string) if (!wlist->wl_next) { cend[stackp]->co_numtimes = -1; } else { - char *s; + char *s = "1"; double val; struct wordlist *t; /*CDHW*/ /*CDHW wlist = cp_variablesubst(cp_bquote(cp_doglob(wl_copy(wlist)))); Wrong order? Leak? CDHW*/ t = cp_doglob(cp_bquote(cp_variablesubst(wl_copy(wlist)))); /*CDHW leak from cp_doglob? */ - s = t->wl_next->wl_word; + + if (!t->wl_next) { + fprintf(cp_err, "Error: Undefined number after command 'repeat', assume 1\n"); + } + else + s = t->wl_next->wl_word; if (ft_numparse(&s, FALSE, &val) > 0) { /* Can be converted to int */