Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Fix crash with bracketed-paste-magic and undo



In particular, fc -P/-p didn't interact well with undo. Make sure we
store/restore histline across those calls.

---

I think this should fix it, and hopefully not break anything else.

BTW, if you don't need any of the crazy features in bracketed-paste-magic, I would
recommend using bracketed-paste-url-magic instead.

I also tried some old binaries I had lying around, the crash has happened at least
since 5.3.

 Src/Zle/zle_main.c | 8 ++++++++
 Src/hist.c         | 7 ++++++-
 Src/zsh.h          | 1 +
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index ea88a42475..cb226932b4 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -2185,6 +2185,14 @@ zle_main_entry(int cmd, va_list ap)
 	break;
     }
 
+    case ZLE_CMD_GET_HIST_LINE:
+    {
+	zlong *p = va_arg(ap, zlong *);
+	*p = histline;
+
+	break;
+    }
+
     case ZLE_CMD_PREEXEC:
 	mark_output(1);
 	break;
diff --git a/Src/hist.c b/Src/hist.c
index de21a4ff64..c353601bf0 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -231,6 +231,7 @@ static struct histsave {
     HashTable histtab;
     Histent hist_ring;
     zlong curhist;
+    zlong histline;
     zlong histlinect;
     zlong histsiz;
     zlong savehistsiz;
@@ -3873,6 +3874,10 @@ pushhiststack(char *hf, zlong hs, zlong shs, int level)
     h->histsiz = histsiz;
     h->savehistsiz = savehistsiz;
     h->locallevel = level;
+    if (zleactive)
+	zleentry(ZLE_CMD_GET_HIST_LINE, &h->histline);
+    else
+	h->histline = 0;
 
     memset(&lasthist, 0, sizeof lasthist);
     if (hf) {
@@ -3925,7 +3930,7 @@ pophiststack(void)
     hist_ring = h->hist_ring;
     curhist = h->curhist;
     if (zleactive)
-	zleentry(ZLE_CMD_SET_HIST_LINE, curhist);
+	zleentry(ZLE_CMD_SET_HIST_LINE, h->histline);
     histlinect = h->histlinect;
     histsiz = h->histsiz;
     savehistsiz = h->savehistsiz;
diff --git a/Src/zsh.h b/Src/zsh.h
index c9dc413a21..29dbb5e692 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -3239,6 +3239,7 @@ enum {
     ZLE_CMD_SET_KEYMAP,
     ZLE_CMD_GET_KEY,
     ZLE_CMD_SET_HIST_LINE,
+    ZLE_CMD_GET_HIST_LINE,
     ZLE_CMD_PREEXEC,
     ZLE_CMD_POSTEXEC,
     ZLE_CMD_CHPWD
-- 
2.38.1





Messages sorted by: Reverse Date, Date, Thread, Author