From 0d5b514e636357073904dc8262a9bb772718ac2b Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 5 Jul 2015 17:04:26 +0000 Subject: [PATCH] =?UTF-8?q?now=20removes=20*all*=20trailing=20newlines=20(?= =?UTF-8?q?by=20reusing=20histsave=20result,=20saves=20code),=20plus=20plu?= =?UTF-8?q?gs=20an=20ancient=20memory=20leak=20(hist=5Fexecute=20afree?= =?UTF-8?q?=E2=80=99s=20its=20arg=20now);=20also=20partial=20revert=20of?= =?UTF-8?q?=20commitid=2078014291f06497b3=20as=20COMPLEX=5FHISTORY=20handl?= =?UTF-8?q?es=20multi-line=20commands=20correctly=20now=20(r1.4,=202005-05?= =?UTF-8?q?-23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check.t | 6 +++--- histrap.c | 17 +++++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/check.t b/check.t index c37d63f..53f1ba1 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.696 2015/07/05 15:12:04 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.697 2015/07/05 17:04:24 tg Exp $ # -*- mode: sh -*- #- # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, @@ -3582,7 +3582,7 @@ expected-stdout: a new line 1 echo abc def 2 echo FOOBAR def - 3 echo a new line + echo a new line expected-stderr-pattern: /^X*echo FOOBAR def\necho a new line\nX*$/ --- @@ -3664,7 +3664,7 @@ expected-stdout: a new line 1 echo abc def 2 echo FOOBAR def - 3 echo a new line + echo a new line expected-stderr-pattern: /^X*13\n32\necho FOOBAR def\necho a new line\nX*$/ --- diff --git a/histrap.c b/histrap.c index fdad711..4e3136d 100644 --- a/histrap.c +++ b/histrap.c @@ -27,7 +27,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.145 2015/07/05 16:48:28 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.146 2015/07/05 17:04:26 tg Exp $"); Trap sigtraps[ksh_NSIG + 1]; static struct sigaction Sigact_ign; @@ -38,7 +38,7 @@ static int writehistline(int, int, const char *); static void writehistfile(int, const char *); #endif -static int hist_execute(char *); +static int hist_execute(char *, Area *); static char **hist_get(const char *, bool, bool); static char **hist_get_oldest(void); @@ -223,7 +223,7 @@ c_fc(const char **wp) xp += len; line = Xclose(xs, xp); } - return (hist_execute(line)); + return (hist_execute(line, ATEMP)); } if (editor && (lflag || nflag)) { @@ -360,13 +360,13 @@ c_fc(const char **wp) shf_close(shf); *xp = '\0'; strip_nuls(Xstring(xs, xp), Xlength(xs, xp)); - return (hist_execute(Xstring(xs, xp))); + return (hist_execute(Xstring(xs, xp), hist_source->areap)); } } -/* Save cmd in history, execute cmd (cmd gets trashed) */ +/* save cmd in history, execute cmd (cmd gets afree’d) */ static int -hist_execute(char *cmd) +hist_execute(char *cmd, Area *areap) { static int last_line = -1; Source *sold; @@ -381,6 +381,11 @@ hist_execute(char *cmd) } histsave(&hist_source->line, cmd, true, true); + /* now *histptr == cmd without all trailing newlines */ + afree(cmd, areap); + cmd = *histptr; + /* pdksh says POSIX doesn’t say this is done, testsuite needs it */ + shellf("%s\n", cmd); /*- * Commands are executed here instead of pushing them onto the