Dear fellow monks,

I get a Segmentation Fault (SIGSEGV) from perl when running the below snippet.

I see nothing in this code why it should do that. Do you have any explanation.

perl -we '$_ = ""; $/ = \4096; while (defined($_.=<>)) { /([\x20-\x7e] +*\z)/ and $_ = $1; }' /dev/urandom

As its input is random, I sometimes have to wait more to get the segv, somtimes I get it very soon. This is a stripped-down example, so it does not do any useful. When giving it a finite file instead of /dev/random it migth get in an infinite busy-loop when giving it a finite file instead of /dev/random (which is the expected behaiviour) or it might segfault.

I am running perl v5.8.5 built for i686-linux, but I can get the same error from v5.8.2 too.

Update: removed a line break from the command. Probably does not matter at all, but you can never now in such cases. Update: please report whether you can reproduce the segfault at all, even if you have no idea why it happens. Maybe it's just a fault on my side.


In reply to Segmentation fault when doing /match/ and $_=$1 by ambrus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.