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

Re: Crash with =~ in script, but not interactively



On Fri, 4 Jan 2008 10:27:40 +0100
"Mikael Magnusson" <mikachu@xxxxxxxxx> wrote:
> I was going to make a wrapper script that replaces the :43: in gcc
> warnings with +43 so i can open in vim easierly, but ran into some
> problems.
> 
> #!/bin/zsh
> #this makes zsh segfault
> if [[ $#@ = 1 ]]; then
> 	if [[ $1 =~ /?[^/]+:[0-9]+:$ ]]; then
> 		echo hello
> 	fi
> fi
> 
> If i save that in a file and run 'zsh file' it crashes, but if i run
> 'source file' in an open shell it works as expected.

Thanks, the problem was fairly obvious (luckily, since debugging the
wordcode is another thing that's a nightmare).

Index: Src/text.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/text.c,v
retrieving revision 1.20
diff -u -r1.20 text.c
--- Src/text.c	1 May 2007 22:05:06 -0000	1.20
+++ Src/text.c	4 Jan 2008 14:28:51 -0000
@@ -732,7 +732,8 @@
 			    taddstr(" ");
 			    taddstr(ecgetstr(state, EC_NODUP, NULL));
 			    if (ctype == COND_STREQ ||
-				ctype == COND_STRNEQ)
+				ctype == COND_STRNEQ ||
+				ctype == COND_REGEX)
 				state->pc++;
 			} else {
 			    /* Unary test: `-f foo' etc. */ 
Index: Test/C02cond.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/C02cond.ztst,v
retrieving revision 1.19
diff -u -r1.19 C02cond.ztst
--- Test/C02cond.ztst	13 Dec 2007 21:21:29 -0000	1.19
+++ Test/C02cond.ztst	4 Jan 2008 14:28:51 -0000
@@ -211,6 +211,18 @@
 0:-nt shouldn't abort on non-existent files
 >status = 1
 
+# core dumps on failure
+  if zmodload -i zsh/regex 2>/dev/null; then
+     echo >regex_test.sh 'if [[ $# = 1 ]]; then
+	if [[ $1 =~ /?[^/]+:[0-9]+:$ ]]; then
+	  :
+	fi
+      fi
+      exit 0'
+      $ZTST_testdir/../Src/zsh -f ./regex_test.sh
+  fi
+0:regex tests shouldn't crash
+
 %clean
   # This works around a bug in rm -f in some versions of Cygwin
   chmod 644 unmodish



-- 
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