You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bogus read after seek beyond end of string based file #10783
Note that in the 5.12.2 case the string file test reports 5 bytes read after
the seek and eof is false. 5.10.0 reports 0 bytes read and eof true as
expected.
Activity
p5pRT commentedon Oct 30, 2010
From peter.jaquiery@ihug.co.nz
Created by peter.jaquiery@ihug.co.nz
A read on a string based file handle incorrectly succeeds following a seek
beyond
the end of the string. The following code demonstrates the issue:
-------- 8< -----------
#!/home/vmware/perl/perl
use strict;
use warnings;
my $str = '1234567890';
print "String file test\n";
open my $strIn, '<', \$str;
test ($strIn);
close $strIn;
open my $outFile, '>', 'temp.txt';
print $outFile $str;
close $outFile;
print "Disk file test\n";
open my $fileIn, '<', 'temp.txt';
test ($fileIn);
close $fileIn;
unlink 'temp.txt';
sub test {
my ($fh) = @_;
seek $fh, 5, 1;
my $ok = read $fh, my $buffer, 5;
printf "Ok: %d, \$buffer: >%s<, eof: %d, tell: %d\n", $ok, $buffer,
eof ($fh), tell ($fh);
seek $fh, 5, 1;
$ok = read $fh, $buffer, 5;
printf "Ok: %d, \$buffer: >%s<, eof: %d, tell: %d\n", $ok, $buffer,
eof ($fh), tell ($fh);
}
-------- 8< -----------
For an Active State build of 5.10.1 the code prints:
String file test
Ok: 5, $buffer: >67890<, eof: 1, tell: 10
Ok: 0, $buffer: ><, eof: 1, tell: 15
Disk file test
Ok: 5, $buffer: >67890<, eof: 1, tell: 10
Ok: 0, $buffer: ><, eof: 1, tell: 15
For the test 5.12.2 exhibiting the problem the code prints:
String file test
Ok: 5, $buffer: >67890<, eof: 1, tell: 10
Ok: 5, $buffer: > ><, eof: 0, tell: 20
Disk file test
Ok: 5, $buffer: >67890<, eof: 1, tell: 10
Ok: 0, $buffer: ><, eof: 1, tell: 15
Note that in the 5.12.2 case the string file test reports 5 bytes read after
the seek and eof is false. 5.10.0 reports 0 bytes read and eof true as
expected.
Perl Info
p5pRT commentedon Nov 27, 2010
From @cpansprout
Fixed by ab9f158.
p5pRT commentedon Nov 27, 2010
@cpansprout - Status changed from 'new' to 'resolved'