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

[perl #132645] Array names starting with 'Inf' can be poorlybehaved.

Thread Next
From:
Father Chrysostomos via RT
Date:
December 23, 2017 02:16
Subject:
[perl #132645] Array names starting with 'Inf' can be poorlybehaved.
Message ID:
rt-4.0.24-9102-1513995356-1225.132645-15-0@perl.org
On Fri, 22 Dec 2017 14:01:29 -0800, jkeenan wrote:
> On Fri, 22 Dec 2017 17:41:56 GMT, public@khwilliamson.com wrote:
> > I am posting this for Dan Book, who is having trouble getting email
> > to
> > perlbug through.
> >
> > The build options and version of perl is immaterial here, except
> > since 5.22.
> >
> > When the warning "Scalar value @arrayname[0] better written as
> > $arrayname[0]"
> > is triggered (any time an array slice is used with only one element),
> > this results
> > in an error if the array's name starts with 'inf'. Code to reproduce:
> >
> > use warnings;
> > my @infasdf;
> > my @x = @infasdf[0];
> > 1
> >
> > Error from above code (since 5.22): Cannot printf Inf with 'c' at
> > (IRC)
> > line 3.
> 
> Bisection points to:
> 
> #####
> 3396ed3031889b7a6890cbcb14149feb7f1ed41f is the first bad commit
> commit 3396ed3031889b7a6890cbcb14149feb7f1ed41f
> Author: Jarkko Hietaniemi <jhi@iki.fi>
> Date:   Sun Jan 25 12:27:44 2015 -0500
> 
> infnan: Simplify inf parsing.
> 
> Accept anything beginning with /^inf/i,
> but warn if there's trailing stuff.
> #####

If I change the array name to @inf, then it points to me:

354b74ae6f54fdd18bcf40fc3afcdaddc8b2ca9d is the first bad commit
commit 354b74ae6f54fdd18bcf40fc3afcdaddc8b2ca9d
Author: Father Chrysostomos <sprout@cpan.org>
Date:   Sat Sep 27 06:48:04 2014 -0700

    [perl #12285] Fix str vs num inf/nan treatment
    
    sprintf, pack and chr were treating 0+"Inf" and "Inf" differently,
    even though they have the same string and numeric values.
    
    pack was also croaking for 0+"Inf" passed to a string format.

That commit corrected much wrong logic, but missed one bit.  The result was that any time perl’s printf mechanism is called at the C level (not directly from Perl code) with a format containing %s followed by a numeric format, it will croak if the string is ‘inf’.

$ ./perl -Ilib -we 'sub in; @{in}'
Ambiguous use of @{in} resolved to @in at -e line 1.
Useless use of a variable in void context at -e line 1.
$ ./perl -Ilib -we 'sub inf; @{inf}'
Cannot printf Inf with 'c' at -e line 1.

-- 

Father Chrysostomos


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

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