This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #31767] open $1, "file" doesn't raise an exception
authorDave Mitchell <davem@fdisolutions.com>
Thu, 30 Sep 2004 20:51:31 +0000 (20:51 +0000)
committerDave Mitchell <davem@fdisolutions.com>
Thu, 30 Sep 2004 20:51:31 +0000 (20:51 +0000)
p4raw-id: //depot/perl@23342

pp.c
t/io/open.t

diff --git a/pp.c b/pp.c
index 772954e..94a278a 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -159,6 +159,8 @@ PP(pp_rv2gv)
                /* If this is a 'my' scalar and flag is set then vivify
                 * NI-S 1999/05/07
                 */
+               if (SvREADONLY(sv))
+                   Perl_croak(aTHX_ PL_no_modify);
                if (PL_op->op_private & OPpDEREF) {
                    char *name;
                    GV *gv;
index 5e1b5ec..e12b447 100755 (executable)
@@ -12,7 +12,7 @@ use Config;
 $Is_VMS = $^O eq 'VMS';
 $Is_MacOS = $^O eq 'MacOS';
 
-plan tests => 107;
+plan tests => 108;
 
 my $Perl = which_perl();
 
@@ -315,3 +315,9 @@ fresh_perl_is(
     'sub f { open(my $fh, "xxx"); $fh = "f"; } f; f;print "ok"',
     'ok', { stderr => 1 },
     '#29102: Crash on assignment to lexical filehandle');
+
+# [perl #31767] Using $1 as a filehandle via open $1, "file" doesn't raise
+# an exception
+
+eval { open $99, "foo" };
+like($@, qr/Modification of a read-only value attempted/, "readonly fh");