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
bulk 88
October 26, 2012 23:48
found a sv_setpvn(sv, (SvPOKp(sv2) ? SvPVX(sv2) : NULL)+1,SvCUR(sv2)-1)
Message ID:

At this line 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) {
    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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About