friguzzi/aleph

Missing cut in repeat loop

Closed this issue · 2 comments

The repeat loop in the following clause is missing a cut (found by the Logtalk linter):

aleph/prolog/aleph.pl

Lines 11272 to 11278 in 26eef74

show_file(File):-
aleph_open(File,read,Stream),
repeat,
read(Stream,Clause),
(Clause = end_of_file -> close(Stream);
writeq(Clause), write('.'), nl,
fail).

Backtracking to a call to show_file/1 will result in a runtime error (trying to read from a closed stream). Tp prevent this from happening, you can rewrite the clause as:

show_file(File):- 
    aleph_open(File,read,Stream),  
    repeat, 
    read(Stream,Clause), 
    (   Clause = end_of_file -> close(Stream), !
    ;   writeq(Clause), write('.'), nl, fail
    ).

Thanks, fixed in 26eef74

Sorry, it's fixed in 4ae3dd8