[m-rev.] diff: fix an abort in read_binary_file_as_bitmap
Julien Fischer
jfischer at opturion.com
Sun Sep 29 03:04:58 AEST 2019
Fix an abort in read_binary_file_as_bitmap.
Reading a bitmap from a binary file stream where the stream is already at EOF
causes an abort rather than returning an empty bitmap in the case where the
file is a regular file. (The case where the stream is not a regular file is
already handled correctly.)
library/io.m:
Fix the above problem.
tests/hard_coded/read_bitmap_size.{m,exp}:
Extend this test case to check for the above.
Julien.
diff --git a/library/io.m b/library/io.m
index a4469b2..995ddd7 100644
--- a/library/io.m
+++ b/library/io.m
@@ -3605,19 +3605,23 @@ read_binary_file_as_bitmap(Stream, Result, !IO) :-
RemainingSize = FileSize - CurrentOffset,
some [!BM] (
!:BM = bitmap.init(RemainingSize * bits_per_byte),
- read_bitmap(Stream, 0, RemainingSize,
- !BM, BytesRead, ReadResult, !IO),
- (
- ReadResult = ok,
- ( if BytesRead = RemainingSize then
- Result = ok(!.BM)
- else
- Result = error(io_error(
+ ( if RemainingSize = 0 then
+ Result = ok(!.BM)
+ else
+ read_bitmap(Stream, 0, RemainingSize, !BM, BytesRead,
+ ReadResult, !IO),
+ (
+ ReadResult = ok,
+ ( if BytesRead = RemainingSize then
+ Result = ok(!.BM)
+ else
+ Result = error(io_error(
"io.read_binary_file_as_bitmap: incorrect file size"))
+ )
+ ;
+ ReadResult = error(Msg),
+ Result = error(Msg)
)
- ;
- ReadResult = error(Msg),
- Result = error(Msg)
)
)
else
diff --git a/tests/hard_coded/read_bitmap_size.exp b/tests/hard_coded/read_bitmap_size.exp
index 5be7515..95bb8c7 100644
--- a/tests/hard_coded/read_bitmap_size.exp
+++ b/tests/hard_coded/read_bitmap_size.exp
@@ -3,3 +3,4 @@ SKIP 1: 00000010.00000100.00001000.00010000.00100000.01000000.10000000.11111111
SKIP 2: 00000100.00001000.00010000.00100000.01000000.10000000.11111111
SKIP 4: 00010000.00100000.01000000.10000000.11111111
SKIP 8: 11111111
+SKIP 9:
diff --git a/tests/hard_coded/read_bitmap_size.m b/tests/hard_coded/read_bitmap_size.m
index 3c63bce..05791be 100644
--- a/tests/hard_coded/read_bitmap_size.m
+++ b/tests/hard_coded/read_bitmap_size.m
@@ -40,7 +40,8 @@ main(!IO) :-
do_test(1, !IO),
do_test(2, !IO),
do_test(4, !IO),
- do_test(8, !IO)
+ do_test(8, !IO),
+ do_test(9, !IO)
;
OpenResult = error(IOError),
io.error_message(IOError, Msg),
More information about the reviews
mailing list