Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: substr outside of string?

by ikegami (Pope)
on Jun 16, 2013 at 15:44 UTC ( #1039215=note: print w/replies, xml ) Need Help??

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

$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.

Replies are listed 'Best First'.
Re^2: substr outside of string?
by ikegami (Pope) on Jun 16, 2013 at 16:04 UTC
    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); ... }
Re^2: substr outside of string?
by BrowserUk (Pope) on Jun 16, 2013 at 16:04 UTC
    $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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039215]
NodeReaper practices with his stiletto

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2018-06-19 01:47 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.