in reply to List::MoreUtils' minmax bug?

I can kinda sorta reproduce this, but this probably isn't the same as your problem:

use warnings; use strict; use List::MoreUtils 'minmax'; my $envres = [ [], [], [{time=>0.002},{}] ]; my ($min, $max) = minmax(map {$_->{time}} @{$envres->[2]}); use Data::Dump 'dump'; dump $min, $max; __END__ Use of uninitialized value in subroutine entry at - line 5. Use of uninitialized value in subroutine entry at - line 5. (undef, 0.002)

I smell a bug... what version of Perl and what version of List::MoreUtils?

Also, are you feeding minmax plain scalars, or are they objects/tied vars/some other magical things? (See Devel::Peek)

Replies are listed 'Best First'.
Re^2: List::MoreUtils' minmax bug?
by perlancar (Hermit) on Mar 16, 2016 at 18:02 UTC

    I'm on perl 5.22.0 and List::MoreUtils 0.413.

    Dumping $envres->[2][0]{time} with Devel::Peek reveals something:

    When there is no warning:

    SV = PVNV(0x279ae10) at 0x25ca100 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) IV = 0 NV = 0.00217268600128591 PV = 0x2895f60 "0.0022"\0 CUR = 6 LEN = 10 COW_REFCNT = 3

    When there is a warning:

    SV = PVNV(0x196bf40) at 0x170b110 REFCNT = 1 FLAGS = (POK,pPOK) IV = 0 NV = 0.002889619519036 PV = 0x1a6dbb0 "0.003"\0 CUR = 5 LEN = 10 Use of uninitialized value $max in numeric le (<=) at lib/Bencher/Form +atter/ScaleTime.pm line 30.

    Trying this with a few other perls: doesn't happen in 5.10.1, always seems to happen in 5.18.4, never seems to happen in 5.20.3 happens too in 5.20.3.

      Wow, Bencher::Backend has a lot of code, it's difficult to tell where $envres comes from. Unfortunately I think you'll need to boil it down to a code snippet that reproduces the problem (which still smells like a bug).

      I did notice that in one place $envres comes from JSON. Here's an interesting one...

      use warnings; use strict; use List::MoreUtils 'minmax'; use JSON::MaybeXS 'decode_json'; use Data::Dump 'dump'; my $envres = decode_json( q# [ [], [], [{"time":"0.0022"},{"time":false}] ] # ); dump $envres; my ($min, $max) = minmax(map {$_->{time}} @{$envres->[2]}); dump $min, $max; __END__ [ [], [], [ { time => 0.0022 }, { time => bless(do{\(my $o = 0)}, "JSON::PP::Boolean") }, ], ] Segmentation fault (core dumped)
        Nope, JSON is not involved in this case. I am now able to produce a simpler test case, I'm updating my original post.
Re^2: List::MoreUtils' minmax bug?
by Anonymous Monk on Mar 16, 2016 at 18:32 UTC

    Reproduce what bug? Where is the bug?

    use List::MoreUtils 'minmax'; use Data::Dump 'dump'; dump minmax(0.002, undef);