Rafael Garcia-Suarez wrote:
Stas Bekman wrote:

But you forget that nobody is going pass SVt_PVBM scalar to print(). Why would they? Do you have a concrete example of someone trying to send a scalar of type > PV to print? Rafael, can you think of such an example?


Reference to magic scalars ? (\$1)
to arrays ? to hashes ? to globs ? to subroutines ?
to lvalues ? (\substr("foo",1,1))

write_client in mp1 does:


    for(i = 1; i <= items - 1; i++) {
        SV *sv = SvROK(ST(i)) && (SvTYPE(SvRV(ST(i))) == SVt_PV) ?
                 (SV*)SvRV(ST(i)) : ST(i);
        buffer = SvPV(sv, len);
        ... print buffer ...
    }

If you pass any of the above suggested entries to the current code (before the change) it'll print the ref value (i.e. you won't pass any of these values). If we change the code to be >= SVt_PV it still won't work, so I can't see what could this change break.

May be to be on the safe side we should check >= SVt_PV and SvPVOK?


Yes. SvPOK, even :)

oops, right. I think coercing with SvPV(sv, len) is just fine.


Actually I think the current code has another bug. If you do:

  my $x = 1;
  print(\$x);

I'd expect it to print 1 and it won't, because $x is IV and not PV. So I'd completely drop any checks for PV, and coerce any reference into PV, like so:

        SV *sv = SvROK(ST(i)) ? (SV*)SvRV(ST(i)) : ST(i);
        buffer = SvPV(sv, len);

(please everyone note that I haven't tested that my suggested change
even compiles, not mentioning writing regression tests and such :)

chuckle, mp1 has a very limited test suite...


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


-- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html



Reply via email to