* Crash with =~ in script, but not interactively
@ 2008-01-04 9:27 Mikael Magnusson
2008-01-04 10:35 ` Mikael Magnusson
2008-01-04 14:42 ` Peter Stephenson
0 siblings, 2 replies; 5+ messages in thread
From: Mikael Magnusson @ 2008-01-04 9:27 UTC (permalink / raw)
To: zsh-workers
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. Here's a
backtrace with -g3 -O0
Program received signal SIGSEGV, Segmentation fault.
0x080d0d16 in taddstr (s=0xc93fa008 <Address 0xc93fa008 out of
bounds>) at text.c:68
68 int sl = strlen(s);
(gdb) bt
#0 0x080d0d16 in taddstr (s=0xc93fa008 <Address 0xc93fa008 out of
bounds>) at text.c:68
#1 0x080d1ce2 in gettext2 (state=0xafb7dc3c) at text.c:538
#2 0x080d1008 in getjobtext (prog=0xa7f11480, c=0xa7f114bc) at text.c:172
#3 0x0807656b in execpline2 (state=0xafb7e22c, pcode=259, how=18,
input=0, output=0, last1=0)
at exec.c:1481
#4 0x0807597b in execpline (state=0xafb7e22c, slcode=26626, how=18,
last1=0) at exec.c:1275
#5 0x080751df in execlist (state=0xafb7e22c, dont_change_job=0,
exiting=0) at exec.c:1081
#6 0x08074dee in execode (p=0xa7f11480, dont_change_job=0, exiting=0)
at exec.c:939
#7 0x0808ddb6 in loop (toplevel=1, justonce=0) at init.c:181
#8 0x08090f15 in zsh_main (argc=2, argv=0xafb7e384) at init.c:1352
#9 0x0805ead6 in main (argc=Cannot access memory at address 0xffffffff
) at ./main.c:93
(gdb) bt full
#0 0x080d0d16 in taddstr (s=0xc93fa008 <Address 0xc93fa008 out of
bounds>) at text.c:68
sl = -918577144
c = 0 '\0'
#1 0x080d1ce2 in gettext2 (state=0xafb7dc3c) at text.c:538
end = (Wordcode) 0xaa0b5378
s = (Tstack) 0x0
n = (Tstack) 0x819bd30
stack = 0
code = 959262863
c1 = {0x815d5ab "=", 0x815d5ad "!=", 0x815d5b0 "<", 0x815d5b2 ">",
0x815d5b4 "-nt",
0x815d5b8 "-ot", 0x815d5bc "-ef", 0x815d5c0 "-eq", 0x815d5c4 "-ne",
0x815d5c8 "-lt",
0x815d5cc "-gt", 0x815d5d0 "-le", 0x815d5d4 "-ge", 0x815d5d8 "=~"}
#2 0x080d1008 in getjobtext (prog=0xa7f11480, c=0xa7f114bc) at text.c:172
s = {prog = 0xa7f11480, pc = 0xa7f11534,
strs = 0xa7f11524 "/\224\217\206/\220+:\2170-9\220+:\205"}
jbuf = "if [[ \205\204@ = 1 ]]; then; if [[ \2051 =~
/\224\217\206/\220+:\2170-9\220+:\205 ]]; then; echo hello; \005rE "
#3 0x0807656b in execpline2 (state=0xafb7e22c, pcode=259, how=18,
input=0, output=0, last1=0)
at exec.c:1481
pid = 134828847
pipes = {2, -1346904904}
#4 0x0807597b in execpline (state=0xafb7e22c, slcode=26626, how=18,
last1=0) at exec.c:1275
ipipe = {0, 0}
opipe = {0, 0}
pj = 0
newjob = 1
old_simple_pline = 0
slflags = 0
code = 259
---Type <return> to continue, or q <return> to quit---
lastwj = 0
lpforked = 0
#5 0x080751df in execlist (state=0xafb7e22c, dont_change_job=0,
exiting=0) at exec.c:1081
donedebug = 0
next = (Wordcode) 0xa7f11520
code = 26626
ret = -1346903576
cj = 0
csp = 0
ltype = 18
old_pline_level = 0
old_list_pipe = 0
oldlineno = 8
oldnoerrexit = 0
donetrap = 0
#6 0x08074dee in execode (p=0xa7f11480, dont_change_job=0, exiting=0)
at exec.c:939
s = {prog = 0xa7f11480, pc = 0xa7f114bc,
strs = 0xa7f11524 "/\224\217\206/\220+:\2170-9\220+:\205"}
#7 0x0808ddb6 in loop (toplevel=1, justonce=0) at init.c:181
toksav = 1
prog = (Eprog) 0xa7f11480
#8 0x08090f15 in zsh_main (argc=2, argv=0xafb7e384) at init.c:1352
t = (char **) 0xafb7e38c
t0 = 157
#9 0x0805ead6 in main (argc=Cannot access memory at address 0xffffffff
) at ./main.c:93
No locals.
Using revision 'Based on 24334: Documentation for run-help
improvements.' which is currently the latest.
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Crash with =~ in script, but not interactively
2008-01-04 9:27 Crash with =~ in script, but not interactively Mikael Magnusson
@ 2008-01-04 10:35 ` Mikael Magnusson
2008-01-04 14:42 ` Peter Stephenson
1 sibling, 0 replies; 5+ messages in thread
From: Mikael Magnusson @ 2008-01-04 10:35 UTC (permalink / raw)
To: zsh-workers
On 04/01/2008, Mikael Magnusson <mikachu@gmail.com> 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. Here's a
> backtrace with -g3 -O0
Just checked, this happens directly on the commit "23375: Phil
Pennock: =~, zsh/regex etc. etc.", so the bug wasn't introduced after
that. Likely the bug is somewhere else, but I can't reproduce it with
just a = instead of the =~.
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Crash with =~ in script, but not interactively
2008-01-04 9:27 Crash with =~ in script, but not interactively Mikael Magnusson
2008-01-04 10:35 ` Mikael Magnusson
@ 2008-01-04 14:42 ` Peter Stephenson
2008-01-04 15:38 ` Mikael Magnusson
1 sibling, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2008-01-04 14:42 UTC (permalink / raw)
To: zsh-workers
On Fri, 4 Jan 2008 10:27:40 +0100
"Mikael Magnusson" <mikachu@gmail.com> 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@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Crash with =~ in script, but not interactively
2008-01-04 14:42 ` Peter Stephenson
@ 2008-01-04 15:38 ` Mikael Magnusson
2008-01-04 15:47 ` Peter Stephenson
0 siblings, 1 reply; 5+ messages in thread
From: Mikael Magnusson @ 2008-01-04 15:38 UTC (permalink / raw)
To: zsh-workers
On 04/01/2008, Peter Stephenson <pws@csr.com> wrote:
> On Fri, 4 Jan 2008 10:27:40 +0100
> "Mikael Magnusson" <mikachu@gmail.com> 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).
Yep that worked. Does the =~ operator support backreferences? I didn't
find anything searching through the manual for the word. This is what
I ended up with instead which works too:
#!/bin/zsh
setopt extendedglob
if [[ $# = 1 ]]; then
if [[ $1 = *[^/]##:(#b)([0-9]##)(#B): ]]; then
2=+${1[$mbegin[1],$mend[1]]}
1=${1[1,$mbegin[1]-2]}
fi
fi
if [[ -z $DISPLAY ]] ; then vim $@; else; gvim $@; fi
in case anyone ever wanted something like that.
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Crash with =~ in script, but not interactively
2008-01-04 15:38 ` Mikael Magnusson
@ 2008-01-04 15:47 ` Peter Stephenson
0 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2008-01-04 15:47 UTC (permalink / raw)
To: zsh-workers
"Mikael Magnusson" wrote:
> Yep that worked. Does the =~ operator support backreferences? I didn't
> find anything searching through the manual for the word. This is what
> I ended up with instead which works too:
It uses $MATCH and $match in the same way (no flags required), unless
the option BASH_REMATCH is set in which case it uses the array
$BASH_REMATCH. See the description of =~ in zshmisc.
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-01-04 15:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-04 9:27 Crash with =~ in script, but not interactively Mikael Magnusson
2008-01-04 10:35 ` Mikael Magnusson
2008-01-04 14:42 ` Peter Stephenson
2008-01-04 15:38 ` Mikael Magnusson
2008-01-04 15:47 ` Peter Stephenson
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).