From 08b43aa1607ed780bd8caddbae019fa1cf6cff32 Mon Sep 17 00:00:00 2001 From: "Steffen (Daode) Nurpmeso" Date: Wed, 3 May 2017 20:58:07 +0200 Subject: [PATCH] FIX off-buffer with only empty input (since 2016-09+!) --- go.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/go.c b/go.c index 8f6401db..749f66ee 100644 --- a/go.c +++ b/go.c @@ -883,25 +883,32 @@ a_go_evaluate(struct a_go_eval_ctx *gecp){ gap = NULL; arglist = arglist_base = n_autorec_alloc(sizeof(*arglist_base) * n_MAXARGC); - line = gecp->gec_line; /* XXX don't change original (buffer pointer) */ + line = gecp->gec_line; /* TODO const-ify original (buffer pointer)! */ assert(line.s[line.l] == '\0'); gecp->gec_add_history = FAL0; /* Aliases that refer to shell commands or macro expansion restart */ jrestart: - /* Strip the white space away from end and beginning of command */ + /* Strip the white space away from end and beginning of command. + * XXX Ideally this will be m_string_trim() */ if(line.l > 0){ size_t i; i = line.l; for(cp = &line.s[i -1]; spacechar(*cp); --cp) - --i; - line.l = i; + if(--i == 0) + break; + line.s[line.l = i] = '\0'; + } + if(line.l > 0){ + for(cp = line.s; spacechar(*cp); ++cp) + ; + line.l -= PTR2SIZE(cp - line.s); + line.s = cp; } - for(cp = line.s; spacechar(*cp); ++cp) - ; - line.l -= PTR2SIZE(cp - line.s); + if(line.l == 0) + goto jempty; /* Ignore null commands (comments) */ if(*cp == '#') @@ -951,6 +958,7 @@ jrestart: * table; while n_PS_SOURCING, however, we ignore blank lines to eliminate * confusion; act just the same for aliases */ if(*word == '\0'){ +jempty: if((n_pstate & n_PS_ROBOT) || !(n_psonce & n_PSO_INTERACTIVE) || gap != NULL) goto jret0; -- 2.11.4.GIT