View Issue Details

IDProjectCategoryView StatusLast Update
0035136FPCRTLpublic2020-10-18 18:49
Reporterhelbig1 Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformx86_64OSOS X 
Product Version3.0.4 
Fixed in Version3.3.1 
Summary0035136: The function EOF does not comply to ISO Pascal
DescriptionEOF returns true even before the file pointer passes the end of file.
Steps To ReproduceTurn on the ISO mode, compile and run the following program:
program p;
var f: text;
begin
    rewrite(f);
    f^ := 'a';
    put(f);
    reset(f);
    if eof(f) then writeln('premature eof');
    writeln(f^);
    if eof(f) then writeln('premature eof');
    writeln(f^);
    if eof(f) then writeln('premature eof');
    get(f);
    if eof(f) then writeln('eof correctly set') else writeln('eof should be set, but isn''t');
end.
Additional InformationWith this error is a show stopper, if you want to use ISO-Pascal.
TagsNo tags attached.
Fixed in Revision43801
FPCOldBugId
FPCTarget-
Attached Files

Activities

Thaddy de Koning

2019-02-22 18:02

reporter   ~0114348

Last edited: 2019-02-22 18:11

View 3 revisions

This is fixed in 3.2.0.
[edit]
I do not think your code is ISO compliant and contains errors. I miss input and output parameters for one...

helbig1

2019-02-23 20:56

reporter   ~0114375

Nice to know, that this bug is fixed in 3.2.0.

Thaddy de Koning, you are right, the example program is not ISO compliant. It should list the output parameter, because later I used it when calling the writeln procedure. The program header should read:

program p(output);

With this fix the program is ISO compliant, isn't it?

Marco van de Voort

2019-02-24 15:30

manager   ~0114384

In normal FPC "text" files are writeonly. (only typed and untyped files are read/write)

https://www.freepascal.org/docs-html/rtl/system/rewrite.html

What does ISO say about that R/W status of "text" files?

helbig1

2019-02-25 13:56

reporter   ~0114404

Last edited: 2019-03-01 15:06

View 2 revisions

Textfiles are both readable and writeable, like any other file. All external files have to be listed as parameters in the program header and declared as variables, with the two exceptions "input" and "output". If they occur in the parameter list, they are implicitly declared as textfiles. When the input file is used for the first time, it is automatically opened for reading and when output is used for the first time, it is opened for writing. By the way, this works fine with FPC.

Marco van de Voort

2019-02-25 14:28

manager   ~0114409

I think I misread your example, doing put and get after a rewrite. I read over the reset() inbetween.

Wolfgang Helbig

2019-02-25 15:02

reporter   ~0114410

The procedures get and put and the function eof refer to the internal text file f and writeln refers to the external file output.

Florian

2019-12-28 11:36

administrator   ~0120099

I am not sure, if the approach I have chosen is correct. If it does not work as expected, please provide more tests.

Wolfgang Helbig

2020-07-23 18:31

reporter   ~0124281

The eof function works fine with release 3.2.0. The above program does not report premature eof. But get(f) throws runtime error 100 (reading past end of file), which it shouldn't.

Florian

2020-07-24 22:06

administrator   ~0124310

What's the expected result when reading past eof with get? Or do you get an premature rte 100 with get?

Wolfgang Helbig

2020-08-04 15:53

reporter   ~0124545

According to the standard you can safely invoke get(f) as long as eof(f) is false. But f^ will be undefined after the last successful get(f).
Here is an example run that shows the FPC-Error:
$ cat eof.p
{$MODE ISO}
program p;
var f: file of char;
begin
    rewrite(f);
    f^ := 'a';
    put(f);
    reset(f);
    while not eof(f) do
    writeln(f^); get(f)
    end
    {at this point, f^ is undefined}
end.
$ fpc eof.p
$ eof
a
Runtime error 100 at $0000000109BDD479
  $0000000109BDD479

$

According to ISO-Pascal, the runtime error shouldn't be reported.

Wolfgang Helbig

2020-10-11 14:45

reporter   ~0126237

This is still not fixed in 3.2.0:
This program must not stop with runtime error 100!
$ cat eof.p
{$MODE ISO}
program p (output);
var f: file of char;
begin
    rewrite(f);
    f^ := 'a';
    put(f);
    reset(f);
    while not eof(f) do
    begin
    writeln(f^); get(f)
    end;
    {at this point, f^ is undefined}
    writeln(f^)
end.
$ fpc eof.p
$ eof
a
Runtime error 100 at $0000000100366439
  $0000000100366439

But p5 v 1.0 shows another violation from the standard!
$ pcom eof.p5 <eof.p
P5 Pascal compiler vs. 1.0


     1 40 {$MODE ISO}
     2 40 program p (output);
     3 40 var f: file of char;
     4 42 begin
     5 3 rewrite(f);
     6 7 f^ := 'a';
     7 14 put(f);
     8 17 reset(f);
     9 19 while not eof(f) do
    10 23 begin
    11 23 writeln(f^); get(f)
    12 37 end;
    13 38 {at this point, f^ is undefined}
    14 38 writeln(f^)
    15 47 end.

Errors in program: 0
$ pint eof.p5
P5 Pascal interpreter vs. 1.0

Assembling/loading program
Running program

a
a

program complete

It should not print the second a, since whenever eof the value of f^ is invalid.

Florian

2020-10-11 15:02

administrator   ~0126238

Indeed, it is fixed only in 3.3.1

Wolfgang Helbig

2020-10-18 15:03

reporter   ~0126389

See also 0037951 The procedure seek should go one position after the last item.

Marco van de Voort

2020-10-18 18:49

manager   ~0126401

FPC 3.2.1 as of 2020-10-11 prints

a
a
eof correctly set

Issue History

Date Modified Username Field Change
2019-02-22 14:48 helbig1 New Issue
2019-02-22 18:02 Thaddy de Koning Note Added: 0114348
2019-02-22 18:10 Thaddy de Koning Note Edited: 0114348 View Revisions
2019-02-22 18:11 Thaddy de Koning Note Edited: 0114348 View Revisions
2019-02-23 20:56 helbig1 Note Added: 0114375
2019-02-24 15:30 Marco van de Voort Note Added: 0114384
2019-02-25 13:56 helbig1 Note Added: 0114404
2019-02-25 14:28 Marco van de Voort Note Added: 0114409
2019-02-25 15:02 Wolfgang Helbig Note Added: 0114410
2019-03-01 15:06 helbig1 Note Edited: 0114404 View Revisions
2019-12-28 11:36 Florian Assigned To => Florian
2019-12-28 11:36 Florian Status new => resolved
2019-12-28 11:36 Florian Resolution open => fixed
2019-12-28 11:36 Florian Fixed in Version => 3.3.1
2019-12-28 11:36 Florian Fixed in Revision => 43801
2019-12-28 11:36 Florian FPCTarget => -
2019-12-28 11:36 Florian Note Added: 0120099
2020-07-23 18:31 Wolfgang Helbig Note Added: 0124281
2020-07-24 22:06 Florian Note Added: 0124310
2020-08-04 15:53 Wolfgang Helbig Note Added: 0124545
2020-10-11 14:45 Wolfgang Helbig Note Added: 0126237
2020-10-11 15:02 Florian Note Added: 0126238
2020-10-18 15:03 Wolfgang Helbig Note Added: 0126389
2020-10-18 18:49 Marco van de Voort Note Added: 0126401