Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

substr outside of string? (Updated: Fixed in later builds.)

by BrowserUk (Pope)
on Jun 16, 2013 at 15:11 UTC ( #1039208=perlquestion: print w/replies, xml ) Need Help??
BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:

Update: I spent so long tracking this down that when I discovered the cause I posted before doing the proper checks which show it is fixed in later builds. My apologies.

Any explanations for this?

C:\test>perl $a = chr(0); $a x= 2**31; substr( $a, 0, 2**16 ) =~ tr[\0][\1]; substr( $a, 2**16, 2**16 ) =~ tr[\0][\1]; ^Z substr outside of string at - line 2.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re: substr outside of string?
by ikegami (Pope) on Jun 16, 2013 at 15:44 UTC
    $a x= 2**31; creates an empty string, so there's an overflow, so something is using an I32 or IV when it should be using a STRLEN. (If this error occurs on a 64-bit build, then it's an I32 being used.) Any substring starting at a position later than zero therefore starts outside of the string.
      PP(pp_repeat) { ... IV count; <---- ... if (SvIOKp(sv)) { if (SvUOK(sv)) { const UV uv = SvUV_nomg(sv); if (uv > IV_MAX) count = IV_MAX; /* The best we can do? */ <---- WTF else count = uv; } else { const IV iv = SvIV_nomg(sv); if (iv < 0) count = 0; else count = iv; } } else if (SvNOKp(sv)) { const NV nv = SvNV_nomg(sv); if (nv < 0.0) count = 0; else count = (IV)nv; } else count = SvIV_nomg(sv); ... }
      $a x= 2**31; creates an empty string,

      Look again:

      C:\test>perl $a = chr(0); $a x= 2**31; print length $a; substr( $a, 0, 2**16 ) =~ tr[\0][\1]; substr( $a, 2**16, 2**16 ) =~ tr[\0][\1]; ^Z substr outside of string at - line 3. 2147483648

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        On systems with 32-bit IVs, one gets zero. I guess there are two problems, then.
Re: substr outside of string?
by toolic (Bishop) on Jun 16, 2013 at 15:39 UTC
    What perl version? I don't see that message on 5.12.2 or 5.14.2 (update) linux.

    diagnostics?

      5.10.1 64-bit. And yes, it seems to be fixed in later versions.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
      You need to turn on warnings.
        I still don't see the message with warnings.
        This is perl 5, version 12, subversion 2 (v5.12.2) built for x86_64-li +nux and This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-li +nux-thread-multi
Re: substr outside of string?
by ww (Archbishop) on Jun 16, 2013 at 15:51 UTC
    C:\>perl -E "use warnings;$a = chr(0); $a x= 2**31; substr( $a, 0, 2**16 ) =~ tr[\0][\1]; substr( $a, 2**16, 2**16 ) =~ tr[\0][\1];" substr outside of string at -e line 1. Use of uninitialized value in transliteration (tr///) at -e line 1.
    ... and, neither "uninit" nor "outside string" appears for any value less than $a x= 2**31 with AS 5.16.

    If you didn't program your executable by toggling in binary, it wasn't really programming!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1039208]
Approved by toolic
Front-paged by davido
help
Chatterbox?
LanX welcome to the twilight zone ...
[Eily]: LanX well since the onion is your eye you should see it everywhere
[marto]: sounds eye watering
[LanX]: oh your talking about my pic?
[Eily]: marto #SoSad
[holli]: duh
[marto]: I expect you to take a nice photo in Glasgow to replace this one :P
[Eily]: LanX yup, saw it when I checked your current rank
[LanX]: obviously the message is not clear enough if you only notice the onion now. ...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2017-12-14 16:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (398 votes). Check out past polls.

    Notices?