From d4c6760ad383a9419aef88be3abd479ebcfb6d36 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Wed, 12 Oct 2011 20:28:21 -0700 Subject: [PATCH] Mention sort in warnings about sort sub retvals With this commit, $ ./miniperl -we '()=sort { undef } 1,2' Use of uninitialized value at -e line 1. becomes $ ./miniperl -we '()=sort { undef } 1,2' Use of uninitialized value in sort at -e line 1. --- pp_sort.c | 4 ++++ t/lib/warnings/9uninit | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/pp_sort.c b/pp_sort.c index 8dacd74..fafa00a 100644 --- a/pp_sort.c +++ b/pp_sort.c @@ -1764,6 +1764,7 @@ S_sortcv(pTHX_ SV *const a, SV *const b) const I32 oldscopeix = PL_scopestack_ix; I32 result; PMOP * const pm = PL_curpm; + OP * const sortop = PL_op; PERL_ARGS_ASSERT_SORTCV; @@ -1774,6 +1775,7 @@ S_sortcv(pTHX_ SV *const a, SV *const b) CALLRUNOPS(aTHX); if (PL_stack_sp != PL_stack_base + 1) Perl_croak(aTHX_ "Sort subroutine didn't return single value"); + PL_op = sortop; result = SvIV(*PL_stack_sp); while (PL_scopestack_ix > oldscopeix) { LEAVE; @@ -1792,6 +1794,7 @@ S_sortcv_stacked(pTHX_ SV *const a, SV *const b) I32 result; AV * const av = GvAV(PL_defgv); PMOP * const pm = PL_curpm; + OP * const sortop = PL_op; PERL_ARGS_ASSERT_SORTCV_STACKED; @@ -1822,6 +1825,7 @@ S_sortcv_stacked(pTHX_ SV *const a, SV *const b) CALLRUNOPS(aTHX); if (PL_stack_sp != PL_stack_base + 1) Perl_croak(aTHX_ "Sort subroutine didn't return single value"); + PL_op = sortop; result = SvIV(*PL_stack_sp); while (PL_scopestack_ix > oldscopeix) { LEAVE; diff --git a/t/lib/warnings/9uninit b/t/lib/warnings/9uninit index 2673b48..a30352a 100644 --- a/t/lib/warnings/9uninit +++ b/t/lib/warnings/9uninit @@ -632,6 +632,9 @@ my @sort; @sort = sort {$a <=> $b} $m1, $g1; sub sortf {$a-1 <=> $b-1}; @sort = sort &sortf, $m1, $g1; +@sort = sort { undef } 1, 2; +sub frobnicate($$) { undef } +@sort = sort frobnicate 1, 2; EXPECT Use of uninitialized value $m1 in sort at - line 6. Use of uninitialized value $g1 in sort at - line 6. @@ -649,6 +652,8 @@ Use of uninitialized value $m1 in sort at - line 9. Use of uninitialized value $m1 in sort at - line 9. Use of uninitialized value $g1 in sort at - line 9. Use of uninitialized value $g1 in sort at - line 9. +Use of uninitialized value in sort at - line 10. +Use of uninitialized value in sort at - line 11. ######## use warnings 'uninitialized'; my ($m1, $m2, $v); -- 2.7.4