This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Avoid emitting pack("p",...) warning erroneously
authorFather Chrysostomos <sprout@cpan.org>
Fri, 29 Jul 2016 17:41:18 +0000 (10:41 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 29 Jul 2016 19:39:37 +0000 (12:39 -0700)
A value may legitimately be marked SvTEMP even when it is not about
to be freed.

pp_pack.c
t/lib/warnings/pp_pack

index 891d2e2..40c3100 100644 (file)
--- a/pp_pack.c
+++ b/pp_pack.c
@@ -3042,7 +3042,8 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist )
                     * of pack() (and all copies of the result) are
                     * gone.
                     */
-                   if ((SvTEMP(fromstr) || (SvPADTMP(fromstr) &&
+                   if (((SvTEMP(fromstr) && SvREFCNT(fromstr) == 1)
+                        || (SvPADTMP(fromstr) &&
                             !SvREADONLY(fromstr)))) {
                        Perl_ck_warner(aTHX_ packWARN(WARN_PACK),
                                       "Attempt to pack pointer to temporary value");
index 62ae3a9..2034f58 100644 (file)
@@ -34,6 +34,9 @@ Use of uninitialized value $a in scalar dereference at - line 4.
 use warnings 'pack' ;
 sub foo { my $a = "a"; return $a . $a++ . $a++ }
 my $a = pack("p", &foo) ;
+@a = "foo";
+sub bar { pop @{\@_}, pack "p", $a[0] } # This should *not* warn, even
+bar(@a);                                # though $a[0] is SvTEMP.
 no warnings 'pack' ;
 my $b = pack("p", &foo) ;
 EXPECT