develooper Front page | perl.perl5.porters | Postings from December 2016

[perl #130198] chop(@x =~ tr///)

Thread Previous
From:
James E Keenan via RT
Date:
December 31, 2016 00:09
Subject:
[perl #130198] chop(@x =~ tr///)
Message ID:
rt-4.0.24-4494-1483142937-381.130198-15-0@perl.org
On Mon, 28 Nov 2016 11:32:38 GMT, hv wrote:
> This is a bug report for perl from hv@crypt.org,
> generated with the help of perlbug 1.40 running under perl 5.25.7.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> In [perl #124368], Brian reports a second unrelated AFL-generated case
> that happens to hit the same assertion in Perl_sv_2pv_flags(); in
> short:
> 
> % perl -e 'chop(@x =~ tr/1/1/)'
> perl: sv.c:2941: Perl_sv_2pv_flags: Assertion `((svtype)((sv)-
> >sv_flags & 0xff)) != SVt_PVAV && ((svtype)((sv)->sv_flags & 0xff)) !=
> SVt_PVHV && ((svtype)((sv)->sv_flags & 0xff)) != SVt_PVFM' failed.
> Aborted (core dumped)
>  %
> 
> Without -DDEBUGGING:
> 
> % ./miniperl -wle '@x=(1..11); print scalar @x; print @x =~ tr/1/1/;
> print chop(@x =~ tr/1/1/)'
> Applying transliteration (tr///) to @x will act on scalar(@x) at -e
> line 1.
> Applying transliteration (tr///) to @x will act on scalar(@x) at -e
> line 1.
> 11
> 2
> Use of uninitialized value in transliteration (tr///) at -e line 1.
> 0
>  %
> 
> The same works fine on a string, apparently happy to chop the temp
> scalar:
> 
> % ./miniperl -wle '$s="11"; print $s; print $s =~ tr/1/1/; print
> chop($s =~ tr/1/1/)'
> 11
> 2
> 2
>  %
> 
> .. but I note that if you throw a scalar() in there (which I'd have
> expected to have no effect), both cases complain (and in rather dodgy
> style):
> 
> % ./miniperl -wle '@x=(1..11); chop(scalar(@x) =~ tr/1/1/)'
> Can't modify scalar in chop at -e line 1, near "tr/1/1/)
> "
> Execution of -e aborted due to compilation errors.
> % ./miniperl -wle '$s="11"; chop(scalar($s) =~ tr/1/1/)'
> Can't modify scalar in chop at -e line 1, near "tr/1/1/)
> "
> Execution of -e aborted due to compilation errors.
>  %
> 
> I'm not sure now what correct behaviour would be here, or how to make
> it so.
> 

In 'perldoc -f tr', I see no documentation of anything like:

#####
@x =~ tr/1/1/
#####

So if that is essentially undefined behavior, then,

#####
chop(@x =~ tr/1/1/)
#####

would be undefined as well.

-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=130198

Thread Previous


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