develooper Front page | perl.perl5.porters | Postings from October 2012

found a sv_setpvn(sv, (SvPOKp(sv2) ? SvPVX(sv2) : NULL)+1,SvCUR(sv2)-1)

Thread Next
From:
bulk 88
Date:
October 26, 2012 23:48
Subject:
found a sv_setpvn(sv, (SvPOKp(sv2) ? SvPVX(sv2) : NULL)+1,SvCUR(sv2)-1)
Message ID:
COL115-W59318C31D9F8B72CCD1A4DF7D0@phx.gbl

At this line http://perl5.git.perl.org/perl.git/blob/d4fe4ada34b7ac23d9e9662f00850d024e6f9ab7:/op.c#l7052 I noticed something strange. "PadnamePV(name)+1" evaluates to "(SvPOKp(pn) ? SvPVX(pn) : NULL)+1", at that line newSVpvn_utf8 is a macro to newSVpvn_flags, which calls, sv_setpvn with len and the char * untouched by newSVpvn_flags. So basically in op.c, "sv_setpvn(sv, (SvPOKp(sv2) ? SvPVX(sv2) : NULL)+1, SvCUR(sv2)-1)" is written. 

sv_setpvn has
___________________________________________________
    if (!ptr) {
    (void)SvOK_off(sv);
    return;
    }
    else {
        /* len is STRLEN which is unsigned, need to copy to signed */
    const IV iv = len;
    if (iv < 0)
        Perl_croak(aTHX_ "panic: sv_setpvn called with negative strlen %"
               IVdf, iv);
    }
___________________________________________________

But ptr is 1, not 0. So I'm not sure if "PADNAME * name", if it is undef (it is a SV underneath), a SEGV would happen or not (and instead a croak). It looks strange. Not sure if this is a bug, or the current behavior is fine.
 		 	   		  
Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About