summaryrefslogtreecommitdiff
path: root/Src/input.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2015-02-16 17:16:57 +0000
committerPeter Stephenson <pws@zsh.org>2015-02-16 17:16:57 +0000
commit126fb61c7c48edb19b9d771e4e517cef710f8bf1 (patch)
treeaedae1b813cb2910a9b62b6a28d0b30268a6c3ff /Src/input.c
parent041a85243eb6d32e1cd1dc9f11a510c79e151433 (diff)
downloadzsh-126fb61c7c48edb19b9d771e4e517cef710f8bf1.tar.gz
zsh-126fb61c7c48edb19b9d771e4e517cef710f8bf1.zip
34560: Fix $(( that's actually a multiline cmd subst.
Diffstat (limited to 'Src/input.c')
-rw-r--r--Src/input.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/Src/input.c b/Src/input.c
index 9520fdd6d..f919e5757 100644
--- a/Src/input.c
+++ b/Src/input.c
@@ -330,8 +330,37 @@ inputline(void)
}
}
isfirstch = 1;
- /* Put this into the input channel. */
- inputsetline(ingetcline, INP_FREE);
+ if ((inbufflags & INP_APPEND) && inbuf) {
+ /*
+ * We need new input but need to be able to back up
+ * over the old input, so append this line.
+ * Pushing the line onto the stack doesn't have the right
+ * effect.
+ *
+ * This is quite a simple and inefficient fix, but currently
+ * we only need it when backing up over a multi-line $((...
+ * that turned out to be a command substitution rather than
+ * a math substitution, which is a very special case.
+ * So it's not worth rewriting.
+ */
+ char *oinbuf = inbuf;
+ int newlen = strlen(ingetcline);
+ int oldlen = (int)(inbufptr - inbuf) + inbufleft;
+ if (inbufflags & INP_FREE) {
+ inbuf = realloc(inbuf, oldlen + newlen + 1);
+ inbufptr += inbuf - oinbuf;
+ strcpy(inbuf + oldlen, ingetcline);
+ } else {
+ /* Paranoia: don't think this is used */
+ DPUTS(1, "Appending to unallocated input line.");
+ }
+ inbufleft += newlen;
+ inbufct += newlen;
+ inbufflags |= INP_FREE;
+ } else {
+ /* Put this into the input channel. */
+ inputsetline(ingetcline, INP_FREE);
+ }
return 0;
}