zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: <zsh-workers@zsh.org>
Subject: Re: Complex config triggering Segfault in pattern matching code.
Date: Tue, 16 Dec 2014 20:58:00 +0000	[thread overview]
Message-ID: <20141216205800.65a12ef3@pws-pc.ntlworld.com> (raw)
In-Reply-To: <141215153936.ZM17826@torch.brasslantern.com>

On Mon, 15 Dec 2014 15:39:36 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Dec 15,  1:20pm, Jonathan H wrote:
> }
> } It usually is, but for some reason I can't get it to crash in
> } valgrind.
> 
> That'll happen sometimes if the error is related to a signal being
> handled or something like that.  Zsh isn't internally "multi-threaded"
> so the only source of race conditions is signals (including child
> process exits).

I'm not sure we've really identified a solid strategy for this problem.

Maybe this suggests there's something to do with region highlighting
that's particular sensitive.  I didn't see anything of that kind --- I
don't know why it would be different in terms of memory management from
any other array stored by length --- though I did see a couple of
instances of somewhat incautious programming.  I can't believe the new
debug test will pick up anything.
 
> ==7806== 2 errors in context 2 of 2:
> ==7806== Conditional jump or move depends on uninitialised value(s)
> ==7806==    at 0x65A79E7: execzlefunc (zle_main.c:1360)
> ==7806==    by 0x65B8B2C: bin_zle_call (zle_thingy.c:711)
> 
> I have no idea what to do with that one; that line is:
> 
> 	Shfunc shf = (Shfunc) shfunctab->getnode(shfunctab, w->u.fnnam);

You'd expect use of shf to fall over horribly if there was really
something nasty in that line, which presumably it doesn't.

pws

diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index 467629d..415fee6 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -396,8 +396,9 @@ get_region_highlight(UNUSED(Param pm))
     struct region_highlight *rhp;
 
     /* region_highlights may not have been set yet */
-    if (arrsize)
-	arrsize -= N_SPECIAL_HIGHLIGHTS;
+    if (!arrsize)
+	return hmkarray(NULL);
+    arrsize -= N_SPECIAL_HIGHLIGHTS;
     arrp = retarr = (char **)zhalloc((arrsize+1)*sizeof(char *));
 
     /* ignore special highlighting */
@@ -1028,6 +1029,8 @@ zrefresh(void)
     /* this will create region_highlights if it's still NULL */
     zle_set_highlight();
 
+    DPUTS(!region_highlight, "region_highlight not created");
+
     /* check for region between point ($CURSOR) and mark ($MARK) */
     if (region_active) {
 	if (zlecs <= mark) {
diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c
index de91182..e361e5e 100644
--- a/Src/Zle/zle_utils.c
+++ b/Src/Zle/zle_utils.c
@@ -675,35 +675,42 @@ zle_restore_positions(void)
 	zlell = oldpos->ll;
     }
 
-    /* Count number of regions and see if the array needs resizing */
-    for (nreg = 0, oldrhp = oldpos->regions;
-	 oldrhp;
-	 nreg++, oldrhp = oldrhp->next)
-	;
-    if (nreg + N_SPECIAL_HIGHLIGHTS != n_region_highlights) {
-	n_region_highlights = nreg + N_SPECIAL_HIGHLIGHTS;
-	region_highlights = (struct region_highlight *)
-	    zrealloc(region_highlights,
-		     sizeof(struct region_highlight) * n_region_highlights);
-    }
-    oldrhp = oldpos->regions;
-    rhp = region_highlights + N_SPECIAL_HIGHLIGHTS;
-    while (oldrhp) {
-	struct zle_region *nextrhp = oldrhp->next;
-
-	rhp->atr = oldrhp->atr;
-	rhp->flags = oldrhp->flags;
-	if (zlemetaline) {
-	    rhp->start_meta = oldrhp->start;
-	    rhp->end_meta = oldrhp->end;
-	} else {
-	    rhp->start = oldrhp->start;
-	    rhp->end = oldrhp->end;
+    if (oldpos->regions) {
+	/* Count number of regions and see if the array needs resizing */
+	for (nreg = 0, oldrhp = oldpos->regions;
+	     oldrhp;
+	     nreg++, oldrhp = oldrhp->next)
+	    ;
+	if (nreg + N_SPECIAL_HIGHLIGHTS != n_region_highlights) {
+	    n_region_highlights = nreg + N_SPECIAL_HIGHLIGHTS;
+	    region_highlights = (struct region_highlight *)
+		zrealloc(region_highlights,
+			 sizeof(struct region_highlight) * n_region_highlights);
 	}
+	oldrhp = oldpos->regions;
+	rhp = region_highlights + N_SPECIAL_HIGHLIGHTS;
+	while (oldrhp) {
+	    struct zle_region *nextrhp = oldrhp->next;
 
-	zfree(oldrhp, sizeof(*oldrhp));
-	oldrhp = nextrhp;
-	rhp++;
+	    rhp->atr = oldrhp->atr;
+	    rhp->flags = oldrhp->flags;
+	    if (zlemetaline) {
+		rhp->start_meta = oldrhp->start;
+		rhp->end_meta = oldrhp->end;
+	    } else {
+		rhp->start = oldrhp->start;
+		rhp->end = oldrhp->end;
+	    }
+
+	    zfree(oldrhp, sizeof(*oldrhp));
+	    oldrhp = nextrhp;
+	    rhp++;
+	}
+    } else if (region_highlights) {
+	zfree(region_highlights, sizeof(struct region_highlight) *
+	      n_region_highlights);
+	region_highlights  = NULL;
+	n_region_highlights = 0;
     }
 
     zfree(oldpos, sizeof(*oldpos));

pws


  reply	other threads:[~2014-12-16 21:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-13 19:49 Jonathan H
2014-12-13 23:28 ` Bart Schaefer
2014-12-13 23:36   ` Jonathan H
2014-12-14  4:40     ` Bart Schaefer
2014-12-14 18:20       ` Peter Stephenson
2014-12-14 18:43         ` Bart Schaefer
2014-12-15 21:20         ` Jonathan H
2014-12-15 23:39           ` Bart Schaefer
2014-12-16 20:58             ` Peter Stephenson [this message]
2014-12-17 17:18             ` Jonathan H
2014-12-18  6:14               ` Bart Schaefer
2014-12-18 19:09                 ` Peter Stephenson
2014-12-18 19:34                   ` Peter Stephenson
2014-12-29  0:57                   ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141216205800.65a12ef3@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).