Francesco Bonomi wrote:
Dear friends,
I don't know if what I found is a bug or a correct behaviour I don't understand.
The following program halts with error 'attempt ro read past end of file';
program test; var f : file of char; begin rewrite(f,'test.dat'); seek(f,0); f^:='x'; (*GIVES ERROR HERE*) put(f); close(f); end.
I consider it as a bug. The following patch corrects the problem:
--- rts/files.pas.bb 2005-01-30 00:55:45.498296856 +0100 +++ rts/files.pas 2005-01-30 03:40:10.262624728 +0100 @@ -1810,7 +1813,6 @@ if IsReadable (f) and not f^.Status.EOF then begin GetN (f); - CheckReadableNotEOF (f) end else { Buffer cannot be read in. But perhaps someone only wants to
After the patch is applied `fjf490.pas' fails. However, I think that `fjf490.pas' is wrong. At least in standard mode accessing buffer variable when at the end of file is _not_ an error: the postcondition of `get' says that at the end of file value of the file buffer is undefined, and I see no restriction on access to undefined variables.
So, IMHO the following program is correct (and works with the patch):
program fjf490b(Output);
var t: Text; c: Char;
begin Rewrite (t); Reset (t); c := t^; writeln('OK') end.