On Thu, 1 Nov 2001 12:09 -0600, Tye McQueen wrote: > perl -e "print \stat('.')" > > on perl 5.6.0 and 5.6.1 on several platforms (including the one > documented here by perlbug as well as Linux on intel and Sparc, > Solaris, and AIX) gives "Attempt to free unreferenced scalar" or > just throws SIGSEGV. This bug appears to have been introduced > between 5.005_02 and 5.005_03.
The patch below fixes the bug. The OPf_REF flag signals OP_STAT and the other file test operators that the argument is a filehandle. When a reference is constructed, Perl_mod() always sets the OPf_REF flag and stat() will consider the argument to be a filehandle even when it is an expression. Thanks, Radu Greab --- op.c~ Fri Oct 26 17:09:53 2001 +++ op.c Fri Nov 2 15:11:24 2001 @@ -1670,19 +1670,22 @@ goto nomod; break; /* mod()ing was handled by ck_return() */ } - if (type != OP_LEAVESUBLV) - o->op_flags |= OPf_MOD; + if (type != OP_REFGEN || + PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)) { + if (type != OP_LEAVESUBLV) + o->op_flags |= OPf_MOD; - if (type == OP_AASSIGN || type == OP_SASSIGN) - o->op_flags |= OPf_SPECIAL|OPf_REF; - else if (!type) { - o->op_private |= OPpLVAL_INTRO; - o->op_flags &= ~OPf_SPECIAL; - PL_hints |= HINT_BLOCK_SCOPE; + if (type == OP_AASSIGN || type == OP_SASSIGN) + o->op_flags |= OPf_SPECIAL|OPf_REF; + else if (!type) { + o->op_private |= OPpLVAL_INTRO; + o->op_flags &= ~OPf_SPECIAL; + PL_hints |= HINT_BLOCK_SCOPE; + } + else if (type != OP_GREPSTART && type != OP_ENTERSUB + && type != OP_LEAVESUBLV) + o->op_flags |= OPf_REF; } - else if (type != OP_GREPSTART && type != OP_ENTERSUB - && type != OP_LEAVESUBLV) - o->op_flags |= OPf_REF; return o; } --- t/op/stat.t~ Fri Sep 14 18:49:59 2001 +++ t/op/stat.t Fri Nov 2 15:10:47 2001 @@ -9,7 +9,7 @@ use Config; -print "1..58\n"; +print "1..59\n"; $Is_MSWin32 = $^O eq 'MSWin32'; $Is_NetWare = $^O eq 'NetWare'; @@ -281,3 +281,7 @@ if (-f()) {print "ok 58\n";} else {print "not ok 58\n";} unlink 'Op.stat.tmp' or print "# unlink failed: $!\n"; + +# bug id 20011101.069 +my @r = \stat("."); +if (@r == 13) { print "ok 59\n" } else { print "not ok 59\n" }