Re: [ID 20020425.012] segfault when printing to close indirect filehandle
[p5sagit/p5-mst-13.2.git] / t / lib / warnings / pp_hot
CommitLineData
767a6a26 1 pp_hot.c
599cee73 2
2dd78f96 3 print() on unopened filehandle abc [pp_print]
599cee73 4 $f = $a = "abc" ; print $f $a
5
767a6a26 6 Filehandle %s opened only for input [pp_print]
599cee73 7 print STDIN "abc" ;
8
767a6a26 9 Filehandle %s opened only for output [pp_print]
977289e4 10 $a = <STDOUT> ;
599cee73 11
9a7dcd9c 12 print() on closed filehandle %s [pp_print]
599cee73 13 close STDIN ; print STDIN "abc" ;
14
767a6a26 15 uninitialized [pp_rv2av]
599cee73 16 my $a = undef ; my @b = @$a
17
767a6a26 18 uninitialized [pp_rv2hv]
599cee73 19 my $a = undef ; my %b = %$a
20
767a6a26 21 Odd number of elements in hash list [pp_aassign]
599cee73 22 %X = (1,2,3) ;
23
767a6a26 24 Reference found where even-sized list expected [pp_aassign]
599cee73 25 $X = [ 1 ..3 ];
26
767a6a26 27 Filehandle %s opened only for output [Perl_do_readline]
28 open (FH, ">./xcv") ;
29 my $a = <FH> ;
30
31 glob failed (can't start child: %s) [Perl_do_readline] <<TODO
32
9a7dcd9c 33 readline() on closed filehandle %s [Perl_do_readline]
599cee73 34 close STDIN ; $a = <STDIN>;
35
790090df 36 readline() on closed filehandle %s [Perl_do_readline]
37 readline(NONESUCH);
38
767a6a26 39 glob failed (child exited with status %d%s) [Perl_do_readline] <<TODO
40
41 Deep recursion on subroutine \"%s\" [Perl_sub_crush_depth]
6bc102ca 42 sub fred { fred() if $a++ < 200} fred()
599cee73 43
767a6a26 44 Deep recursion on anonymous subroutine [Perl_sub_crush_depth]
6bc102ca 45 $a = sub { &$a if $a++ < 200} &$a
599cee73 46
6bc102ca 47 Possible Y2K bug: about to append an integer to '19' [pp_concat]
48 $x = "19$yy\n";
767a6a26 49
d804643f 50 Use of reference "%s" as array index [pp_aelem]
51 $x[\1]
52
599cee73 53__END__
767a6a26 54# pp_hot.c [pp_print]
4438c4b7 55use warnings 'unopened' ;
599cee73 56$f = $a = "abc" ;
0453d815 57print $f $a;
4438c4b7 58no warnings 'unopened' ;
0453d815 59print $f $a;
599cee73 60EXPECT
2dd78f96 61print() on unopened filehandle abc at - line 4.
599cee73 62########
767a6a26 63# pp_hot.c [pp_print]
4438c4b7 64use warnings 'io' ;
977289e4 65# There is no guarantee that STDOUT is output only, or STDIN input only.
66# Certainly on some BSDs (at least FreeBSD, Darwin, BSDi) file descriptors
67# 1 and 2 are opened read/write on the tty, and the IO layers may reflect this.
68# So we must make our own file handle that is read only.
69my $file = "./xcv" ; unlink $file ;
70open (FH, ">$file") or die $! ;
71close FH or die $! ;
72die "There is no file $file" unless -f $file ;
73open (FH, "<$file") or die $! ;
74print FH "anc" ;
75open(FOO, "<&FH") or die $! ;
76print FOO "anc" ;
37bd1396 77no warnings 'io' ;
977289e4 78print FH "anc" ;
79print FOO "anc" ;
80use warnings 'io' ;
81print FH "anc" ;
82print FOO "anc" ;
83close (FH) or die $! ;
84close (FOO) or die $! ;
85unlink $file ;
599cee73 86EXPECT
977289e4 87Filehandle FH opened only for input at - line 12.
88Filehandle FOO opened only for input at - line 14.
89Filehandle FH opened only for input at - line 19.
90Filehandle FOO opened only for input at - line 20.
599cee73 91########
767a6a26 92# pp_hot.c [pp_print]
4438c4b7 93use warnings 'closed' ;
599cee73 94close STDIN ;
95print STDIN "anc";
69282e91 96opendir STDIN, ".";
97print STDIN "anc";
98closedir STDIN;
4438c4b7 99no warnings 'closed' ;
0453d815 100print STDIN "anc";
69282e91 101opendir STDIN, ".";
102print STDIN "anc";
599cee73 103EXPECT
43693395 104print() on closed filehandle STDIN at - line 4.
105print() on closed filehandle STDIN at - line 6.
106 (Are you trying to call print() on dirhandle STDIN?)
599cee73 107########
f55e507d 108# pp_hot.c [pp_print]
109# [ID 20020425.012] from Dave Steiner <steiner@bakerst.rutgers.edu>
110# This goes segv on 5.7.3
111use warnings 'closed' ;
112my $fh = *STDOUT{IO};
113close STDOUT or die "Can't close STDOUT";
114print $fh "Shouldn't print anything, but shouldn't SEGV either\n";
115EXPECT
116print() on closed filehandle at - line 7.
117########
767a6a26 118# pp_hot.c [pp_rv2av]
4438c4b7 119use warnings 'uninitialized' ;
599cee73 120my $a = undef ;
0453d815 121my @b = @$a;
4438c4b7 122no warnings 'uninitialized' ;
0453d815 123my @c = @$a;
599cee73 124EXPECT
b89fed5f 125Use of uninitialized value in array dereference at - line 4.
599cee73 126########
767a6a26 127# pp_hot.c [pp_rv2hv]
4438c4b7 128use warnings 'uninitialized' ;
599cee73 129my $a = undef ;
0453d815 130my %b = %$a;
4438c4b7 131no warnings 'uninitialized' ;
0453d815 132my %c = %$a;
599cee73 133EXPECT
b89fed5f 134Use of uninitialized value in hash dereference at - line 4.
599cee73 135########
767a6a26 136# pp_hot.c [pp_aassign]
e476b1b5 137use warnings 'misc' ;
599cee73 138my %X ; %X = (1,2,3) ;
e476b1b5 139no warnings 'misc' ;
0453d815 140my %Y ; %Y = (1,2,3) ;
599cee73 141EXPECT
142Odd number of elements in hash assignment at - line 3.
143########
767a6a26 144# pp_hot.c [pp_aassign]
e476b1b5 145use warnings 'misc' ;
599cee73 146my %X ; %X = [1 .. 3] ;
e476b1b5 147no warnings 'misc' ;
0453d815 148my %Y ; %Y = [1 .. 3] ;
599cee73 149EXPECT
150Reference found where even-sized list expected at - line 3.
151########
767a6a26 152# pp_hot.c [Perl_do_readline]
4438c4b7 153use warnings 'closed' ;
69282e91 154close STDIN ; $a = <STDIN> ;
155opendir STDIN, "." ; $a = <STDIN> ;
156closedir STDIN;
4438c4b7 157no warnings 'closed' ;
69282e91 158opendir STDIN, "." ; $a = <STDIN> ;
0453d815 159$a = <STDIN> ;
599cee73 160EXPECT
43693395 161readline() on closed filehandle STDIN at - line 3.
162readline() on closed filehandle STDIN at - line 4.
163 (Are you trying to call readline() on dirhandle STDIN?)
599cee73 164########
767a6a26 165# pp_hot.c [Perl_do_readline]
166use warnings 'io' ;
167my $file = "./xcv" ; unlink $file ;
977289e4 168open (FH, ">$file") or die $! ;
767a6a26 169my $a = <FH> ;
170no warnings 'io' ;
171$a = <FH> ;
977289e4 172use warnings 'io' ;
173open(FOO, ">&FH") or die $! ;
174$a = <FOO> ;
175no warnings 'io' ;
176$a = <FOO> ;
177use warnings 'io' ;
178$a = <FOO> ;
179$a = <FH> ;
180close (FH) or die $! ;
181close (FOO) or die $! ;
767a6a26 182unlink $file ;
183EXPECT
43693395 184Filehandle FH opened only for output at - line 5.
977289e4 185Filehandle FOO opened only for output at - line 10.
186Filehandle FOO opened only for output at - line 14.
187Filehandle FH opened only for output at - line 15.
767a6a26 188########
189# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 190use warnings 'recursion' ;
599cee73 191sub fred
192{
193 fred() if $a++ < 200
194}
4a925ff6 195{
196 local $SIG{__WARN__} = sub {
197 die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
198 };
199 fred();
200}
599cee73 201EXPECT
4a925ff6 202ok
599cee73 203########
767a6a26 204# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 205no warnings 'recursion' ;
0453d815 206sub fred
207{
208 fred() if $a++ < 200
209}
210{
211 local $SIG{__WARN__} = sub {
212 die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
213 };
214 fred();
215}
216EXPECT
217
218########
767a6a26 219# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 220use warnings 'recursion' ;
599cee73 221$b = sub
222{
223 &$b if $a++ < 200
224} ;
225
226&$b ;
227EXPECT
228Deep recursion on anonymous subroutine at - line 5.
0453d815 229########
767a6a26 230# pp_hot.c [Perl_sub_crush_depth]
4438c4b7 231no warnings 'recursion' ;
0453d815 232$b = sub
233{
234 &$b if $a++ < 200
235} ;
236
237&$b ;
238EXPECT
6bc102ca 239########
240# pp_hot.c [pp_concat]
8d6d96c1 241use warnings 'uninitialized';
242my($x, $y);
243sub a { shift }
244a($x . "x"); # should warn once
245a($x . $y); # should warn twice
246$x .= $y; # should warn once
247$y .= $y; # should warn once
248EXPECT
249Use of uninitialized value in concatenation (.) or string at - line 5.
250Use of uninitialized value in concatenation (.) or string at - line 6.
251Use of uninitialized value in concatenation (.) or string at - line 6.
252Use of uninitialized value in concatenation (.) or string at - line 7.
253Use of uninitialized value in concatenation (.) or string at - line 8.
254########
255# pp_hot.c [pp_concat]
e476b1b5 256use warnings 'y2k';
6bc102ca 257use Config;
258BEGIN {
259 unless ($Config{ccflags} =~ /Y2KWARN/) {
260 print "SKIPPED\n# perl not built with -DPERL_Y2KWARN";
261 exit 0;
262 }
263}
264my $x;
265my $yy = 78;
266$x = "19$yy\n";
267$x = "19" . $yy . "\n";
268$x = "319$yy\n";
269$x = "319" . $yy . "\n";
777b0c87 270$yy = 19;
271$x = "ok $yy\n";
272$yy = 9;
273$x = 1 . $yy;
e476b1b5 274no warnings 'y2k';
6bc102ca 275$x = "19$yy\n";
276$x = "19" . $yy . "\n";
277EXPECT
278Possible Y2K bug: about to append an integer to '19' at - line 12.
279Possible Y2K bug: about to append an integer to '19' at - line 13.
d804643f 280########
281# pp_hot.c [pp_aelem]
282{
283use warnings 'misc';
284print $x[\1];
285}
286{
287no warnings 'misc';
288print $x[\1];
289}
290
291EXPECT
292OPTION regex
293Use of reference ".*" as array index at - line 4.
1f1cc344 294########
295# pp_hot.c [pp_aelem]
296package Foo;use overload q("") => sub {};package main;$a = bless {}, "Foo";
297$b = {};
298{
299use warnings 'misc';
300print $x[$a];
301print $x[$b];
302}
303{
304no warnings 'misc';
305print $x[$a];
306print $x[$b];
307}
308
309EXPECT
310OPTION regex
311Use of reference ".*" as array index at - line 7.