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

Re: Segmentation fault while searching backward



On Wed, 19 Dec 2007 00:59:34 +0000 (UTC)
Jörg Sommer <joerg@xxxxxxxxxxxx> wrote:
> when I search backward through the history with ^R I get a segmentation
> fault:

Jörg sent me his history and I can get it to crash, although not quite as
straightforwardly (it needed some scrolling).  The crash I was getting was
in a large chunk of history that needed scrolling to handle.  I think the
fix for that crash is the following depressingly simply change.  (The
second hunk is to be safer in future while still reporting problems when
debugging.)  It's not absolutely certain it's the same problem, but I think
there's a pretty good chance.

I'll make another test build at some point.

Index: Src/Zle/zle_refresh.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_refresh.c,v
retrieving revision 1.51
diff -u -r1.51 zle_refresh.c
--- Src/Zle/zle_refresh.c	5 Jan 2008 13:12:56 -0000	1.51
+++ Src/Zle/zle_refresh.c	8 Jan 2008 14:56:53 -0000
@@ -797,7 +797,7 @@
 		(int)ZR_strlen(nbuf[0]) + rpromptw < winw - 1;
     } else {
 /* insert >.... on first line if there is more text before start of screen */
-	memset(nbuf[0], ZWC(' '), lpromptw);
+	ZR_memset(nbuf[0], ZWC(' '), lpromptw);
 	t0 = winw - lpromptw;
 	t0 = t0 > 5 ? 5 : t0;
 	ZR_memcpy(nbuf[0] + lpromptw, ZWS(">...."), t0);
@@ -1133,6 +1133,15 @@
 	    if (!*ol) {
 		i = (col_cleareol >= 0) ? col_cleareol : nllen;
 		i -= vcs;
+		if (i < 0) {
+		    /*
+		     * This shouldn't be necessary, but it's better
+		     * than a crash if there's a bug somewhere else,
+		     * so report in debug mode.
+		     */
+		    DPUTS(1, "BUG: badly calculated old line width in refresh");
+		    i = 0;
+		}
 		zwrite(nl, i);
 		vcs += i;
 		if (col_cleareol >= 0)


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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