[Israel.pm] segmentation fault in regex

Shlomi Fish shlomif at iglu.org.il
Sun Mar 12 05:33:22 PST 2006


On Sunday 12 March 2006 15:16, Levenglick Dov-RM07994 wrote:
> Obviously I made a mistake. Is should be this:
> s#//.?\n##sg;   # removes single line comments (//...)
> s#/\*.?\*/##sg; # removes multiple line comments (/*...*/)
>

You probably meant "*?" instead of "?". However, the problem with a two stage 
approach is that single line comments may contain "/*" or "*/":

i++; // /*
j--; // */

and as thus removing them will harm the integrity of the processor. Likewise 
for multiple line comments that contain "//". And this is not considering all 
the cases of strings containing comments, etc.

Regards,

	Shlomi Fish


>
> Best Regards,
> Dov Levenglick
> DSP SoC System and Applications Engineer,
> Network and Computing Systems Group
> Freescale Semiconductor Israel
> Tel. +972-9-952-2804
> The information contained in this email is classified as:
> [ ] General Business Information
> [ ] Freescale Internal Use Only
> [ ] Freescale Confidential Propriety
> [x] Personal Memorandum
>
>
> -----Original Message-----
> From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf
> Of Levenglick Dov-RM07994 Sent: Sunday, March 12, 2006 3:13 PM
> To: 'Perl in Israel'
> Subject: RE: [Israel.pm] segmentation fault in regex
>
> I would suggest removing the comments in two stages:
> s#//(.*)\n##sg;  # removes single line comments (//...)
> s#/\*(.*)\*/##sg # removes multiple line comments (/*...*/)
>
> Best Regards,
> Dov Levenglick
> DSP SoC System and Applications Engineer,
> Network and Computing Systems Group
> Freescale Semiconductor Israel
> Tel. +972-9-952-2804
> The information contained in this email is classified as:
> [ ] General Business Information
> [ ] Freescale Internal Use Only
> [ ] Freescale Confidential Propriety
> [x] Personal Memorandum
>
>
> -----Original Message-----
> From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf
> Of Yossi.Itzkovich at ecitele.com Sent: Sunday, March 12, 2006 2:53 PM
> To: Perl in Israel
> Subject: Re: [Israel.pm] segmentation fault in regex
>
> Hi,
> Thanks Eli && Shlomi for your responses.
>
> The complex regex was originally taken from perldoc FAQ how to remove C/C++
> comments. May be I modified it a little (it was 2 years ago, so I don't
> remember).
>
> I am ready to simplify it, as long as it does what it has (no more , no
> less)
>
>
>
>
>
>              Eli Billauer
>              <eli at billauer.co.
>              il>                                                        To
>              Sent by:                  Perl in Israel <perl at perl.org.il>
>              perl-bounces at perl                                          cc
>              .org.il
>                                                                    Subject
>                                        Re: [Israel.pm] segmentation fault
>              12/03/2006 14:49          in regex
>
>
>              Please respond to
>               Perl in Israel
>              <perl at perl.org.il
>
>
>
>
>
>
>
> This is what my Perl v5.6.1 had to say:
>
> --------------------
> $ perl regex_segfault.pl  test_file.txt
> test_file.txt
> Complex regular subexpression recursion limit (32766) exceeded at
> regex_segfault.pl line 7, <FILE> chunk 1.
> --------------------
>
> Your Perl probably wasn't as polite. Maybe you want to downgrade? ;)
>
> My hunch is that you've used an excessively complicated regex to do
> something (I'm not in the mood for deciphering that expression).
>
> Maybe tell us what you want to do, and we'll play "who's got the
> prettiest regex" on it? ;)
>
>     Eli
>
> Yossi.Itzkovich at ecitele.com wrote:
> >OK, let's try.
> >
> >The file is at ftp://ftp.ecitele.com/outgoing/inf_vie.htm
> >
> >
> >
> >The code:
> >#! /usr/local/bin/perl -w
> >my $name=shift;
> >open (FILE,$name) or die "BLA\n";
> >local $/;
> >my $file=<FILE>;
> >print "$name\n";
> >$file=~
> >s~/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|(\"(\\.|[^\"\\])*\"|'(\\.|[^'\\])*
> >'|.[^/"'\\]*)~$2~gs;
> >
> >
> >Any ideas ?
> >
> >Yossi
>
> --
> Web: http://www.billauer.co.il
>
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl

-- 

---------------------------------------------------------------------
Shlomi Fish      shlomif at iglu.org.il
Homepage:        http://www.shlomifish.org/

95% of the programmers consider 95% of the code they did not write, in the
bottom 5%.



More information about the Perl mailing list