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

Re: Complicated segfault regression



On Fri, 03 Jul 2015 14:44:48 +0100
Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
> Yes, it's not the wrap, it's the length that's contributing (but not
> decisive on its own).  However, I can't see any sign of problems in
> the parsing code, and running the function doesn't fail in the same
> castastrophic way.  In fact, nobbling gettext2() entirely, the following
> 
> # --- begin crashing code block ---
> fn() {
>   ac_file="the else branch"
>   case $ac_file in
>     *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
>     *.* ) break;;
>     *)
>     ;;
>   esac
>   print Stuff here
> }
> # --- end crashing code block ---
> 
> runs to conclusion, printing the message, while the "which" output is
> still gibberish.  So there's something at least different about the text
> handling compared with execution that needs tracking down.

I'm horribly out of my depth here, but how about this...

n->pop has no dcoumentation whatsoever, but the calculation associated
with it in 5.0.7 is to do with how much state->pc gets incremented for
each case pattern set, not coutning the string.  Why?  No idea.  The
calculation has changed, and now looks like the following.

pws

diff --git a/Src/text.c b/Src/text.c
index 3287c54..d63141b 100644
--- a/Src/text.c
+++ b/Src/text.c
@@ -681,7 +681,7 @@ gettext2(Estate state)
 	case WC_CASE:
 	    if (!s) {
 		Wordcode end = state->pc + WC_CASE_SKIP(code);
-		wordcode nalts;
+		wordcode nalts, ialts;
 
 		taddstr("case ");
 		taddstr(ecgetstr(state, EC_NODUP, NULL));
@@ -702,21 +702,22 @@ gettext2(Estate state)
 			taddchr(' ');
 		    taddstr("(");
 		    code = *state->pc++;
-		    nalts = *state->pc++;
-		    while (nalts--) {
+		    nalts = ialts = *state->pc++;
+		    while (ialts--) {
 			taddstr(ecgetstr(state, EC_NODUP, NULL));
 			state->pc++;
-			if (nalts)
+			if (ialts)
 			    taddstr(" | ");
 		    }
 		    taddstr(") ");
 		    tindent++;
 		    n = tpush(code, 0);
 		    n->u._case.end = end;
-		    n->pop = (state->pc - 2 + WC_CASE_SKIP(code) >= end);
+		    n->pop = (state->pc - 2 - nalts + WC_CASE_SKIP(code)
+			      >= end);
 		}
 	    } else if (state->pc < s->u._case.end) {
-		wordcode nalts;
+		wordcode nalts, ialts;
 		dec_tindent();
 		switch (WC_CASE_TYPE(code)) {
 		case WC_CASE_OR:
@@ -737,17 +738,17 @@ gettext2(Estate state)
 		    taddchr(' ');
 		taddstr("(");
 		code = *state->pc++;
-		nalts = *state->pc++;
-		while (nalts--) {
+		nalts = ialts = *state->pc++;
+		while (ialts--) {
 		    taddstr(ecgetstr(state, EC_NODUP, NULL));
 		    state->pc++;
-		    if (nalts)
+		    if (ialts)
 			taddstr(" | ");
 		}
 		taddstr(") ");
 		tindent++;
 		s->code = code;
-		s->pop = ((state->pc - 2 + WC_CASE_SKIP(code)) >=
+		s->pop = ((state->pc - 2 - nalts + WC_CASE_SKIP(code)) >=
 			  s->u._case.end);
 	    } else {
 		dec_tindent();



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