[m-rev.] for review: Fix a bug with IO errors while reading files

Julien Fischer jfischer at opturion.com
Mon Aug 29 09:39:25 AEST 2016


Hi Paul,

On Fri, 26 Aug 2016, Paul Bone wrote:

> Fix a bug with IO errors while reading files

s/IO/I\/O/.  (I'm not so worried about the log message, but the code
in library/io.m uses the latter.)

> Mercury did not properly test for IO errors for file reading.  If an IO
> error occurred it would be reported as EOF.  If this happened at just
> the right spot it could be silently ignored.  I found the mistake when
> trying to open a directory as a file.  Opening the file succeeded but
> reading from it incorrectly gave an EOF.
>
> library/io.m:
>    read_char_code has always been documented as returning -1 for EOF
>    and -2 for an error.  But the C code did not correctly implement
>    this.  fgetc will return EOF in either case and the caller must use
>    ferror or feof to determine what has happened.
>
>    Make it clearer that valid characters and bytes from read_char_code
>    must
>    >= 0.
>
>    Conform to changes in the runtime regarding supporting ferror
>
> runtime/mercury_library_types.h:
>    Add MR_FERROR marcro
>
>    Add ferror field to the MercuryFile struct.
>
> runtime/mercury_file.[ch]:
>    Add ferror field to the MercuryFile struct.

The diff looks fine; it would also be useful to add a regression test for
this one.  (Also, I assume you have checked that other backends are not
affected by this?)

Julien.


More information about the reviews mailing list