[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

[perl #56526] m/a{1,0}/ compiles but doesn't match a literal string



# New Ticket Created by  Michael Cartmell 
# Please include the string:  [perl #56526]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=56526 >


This is a bug report for perl from michael@lnx-main.cartmell.net,
generated with the help of perlbug 1.36 running under perl 5.10.0.


-----------------------------------------------------------------
The regular expression /a{2,1}/ fails to compiles the the error
Can't do {n,m} with n > m in regex; marked by <-- HERE in m/a{2,1} <-- 
HERE / at -e line 1.

The regular expression /a{2,-1}/ compiles and matches a literal "a{2,-1}".

The regex /a{2,0}/, however, compiles into a form that must match at least
two "a"s but then fails. I'm guessing because at the point it has 
matched two
"a"s it must also match no more than zero.

michael@lnx-main:perl-5.10.x> perl -Mre=debug -E'say "matched" if "aaa" 
=~ qr/a{2,0}/'
Compiling REx "a{2,0}"
Final program:
    1: CURLY {2,0} (5)
    3:   EXACT <a> (0)
    5: END (0)
anchored "aa" at 0 (checking anchored) minlen 2
Guessing start of match in sv for REx "a{2,0}" against "aaa"
Found anchored substr "aa" at offset 0...
Guessed: match at offset 0
Matching REx "a{2,0}" against "aaa"
    0 <> <aaa>                |  1:CURLY {2,0}(5)
                                   failed...
    1 <a> <aa>                |  1:CURLY {2,0}(5)
                                   failed...
Match failed
Freeing REx: "a{2,0}"

The choices appear to be
1. document this as the expected behaviour.
2. match a literal "a{2,0}", consistent with /a{2,-0}/.
3. make /a{2,0}/ an error, consistent with /a{2,1}/.

This patch make /a{2,0}/ an error and adds a test.

*** perl-5.10.x-orig/regcomp.c	2008-07-02 21:32:25.067518022 +1000
--- perl-5.10.x/regcomp.c	2008-07-02 18:19:28.371522116 +1000
***************
*** 6366,6372 ****
   		*flagp = WORST;
   	    if (max > 0)
   		*flagp |= HASWIDTH;
! 	    if (max && max < min)
   		vFAIL("Can't do {n,m} with n > m");
   	    if (!SIZE_ONLY) {
   		ARG1_SET(ret, (U16)min);
--- 6366,6372 ----
   		*flagp = WORST;
   	    if (max > 0)
   		*flagp |= HASWIDTH;
! 	    if (max < min)
   		vFAIL("Can't do {n,m} with n > m");
   	    if (!SIZE_ONLY) {
   		ARG1_SET(ret, (U16)min);

*** perl-5.10.x-orig/t/op/re_tests	2008-07-02 21:32:18.867512251 +1000
--- perl-5.10.x/t/op/re_tests	2008-07-02 21:16:52.063549753 +1000
***************
*** 618,623 ****
--- 618,624 ----
   ((?>[^()]+)|\([^()]*\))+	((abc(ade)ufh()()x	y	$&	abc(ade)ufh()()x
   (?<=x+)y	-	c	-	Variable length lookbehind not implemented
   a{37,17}	-	c	-	Can't do {n,m} with n > m
+ a{37,0}	-	c	-	Can't do {n,m} with n > m
   \Z	a\nb\n	y	$-[0]	3
   \z	a\nb\n	y	$-[0]	4
   $	a\nb\n	y	$-[0]	3


Regards,
Michael Cartmell
-----------------------------------------------------------------
---
Flags:
     category=core
     severity=low
---
Site configuration information for perl 5.10.0:

Configured by michael at Fri Jun 27 15:55:25 EST 2008.

Summary of my perl5 (revision 5 version 10 subversion 0 patch 34065) 
configuration:
   Platform:
     osname=linux, osvers=2.6.25.5-1.1-default, archname=i686-linux-64int-ld
     uname='linux lnx-main 2.6.25.5-1.1-default #1 smp 2008-06-07 
01:55:22 +0200 i686 athlon i386 gnulinux '
     config_args=''
     hint=recommended, useposix=true, d_sigaction=define
     useithreads=undef, usemultiplicity=undef
     useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
     use64bitint=define, use64bitall=undef, uselongdouble=define
     usemymalloc=y, bincompat5005=undef
   Compiler:
     cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector 
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
     optimize='-O2 -march=athlon-xp',
     cppflags='-fno-strict-aliasing -pipe -fstack-protector 
-I/usr/local/include'
     ccversion='', gccversion='4.3.1 20080507 (prerelease) 
[gcc-4_3-branch revision 135036]', gccosandvers=''
     intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
     ivtype='long long', ivsize=8, nvtype='long double', nvsize=12, 
Off_t='off_t', lseeksize=8
     alignbytes=4, prototype=define
   Linker and Libraries:
     ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
     libpth=/usr/local/lib /lib /usr/lib
     libs=-lnsl -ldl -lm -lcrypt -lutil -lc
     perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
     libc=/lib/libc-2.8.so, so=so, useshrplib=false, libperl=libperl.a
     gnulibc_version='2.8'
   Dynamic Linking:
     dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
     cccdlflags='-fPIC', lddlflags='-shared -O2 -march=athlon-xp 
-L/usr/local/lib -fstack-protector'

Locally applied patches:
     MAINT33535

---
@INC for perl 5.10.0:
     /net/perl/5.10.1-devel/lib/5.10.0/i686-linux-64int-ld
     /net/perl/5.10.1-devel/lib/5.10.0
     /net/perl/5.10.1-devel/lib/site_perl/5.10.0/i686-linux-64int-ld
     /net/perl/5.10.1-devel/lib/site_perl/5.10.0
     .

---
Environment for perl 5.10.0:
     HOME=/home/michael
     LANG=en_GB.UTF-8
     LANGUAGE=
     LD_LIBRARY_PATH (unset)
     LOGDIR (unset)
 
PATH=/net/perl/5.10.1-devel/bin:/home/michael/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/usr/lib/qt3/bin
     PERL_BADLANG (unset)
     SHELL=/bin/bash


Follow-Ups from:
demerphq <demerphq@gmail.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]