[m-rev.] for post-commit review: fix NumCodeUnits != FileStringLen aborts in C#
Peter Wang
novalazy at gmail.com
Fri Mar 11 14:50:11 AEDT 2022
On Fri, 11 Mar 2022 13:15:56 +1100 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
>
> 2022-03-11 13:08 GMT+11:00 "Peter Wang" <novalazy at gmail.com>:
> >> --- a/library/io.m
> >> +++ b/library/io.m
> >> @@ -8755,7 +8755,7 @@ read_file_as_string_and_num_code_units(input_stream(Stream), Result, !IO) :-
> >> NullCharError = bool.NO;
> >> ").
> >>
> >> -read_file_as_string_2(Stream, String, NumCUs, Error, NullCharError, !IO) :-
> >> +read_file_as_string_2(Stream, Str, NumCUs, Error, NullCharError, !IO) :-
> >> % Check if the stream is a regular file; if so, allocate a buffer
> >> % according to the size of the file. Otherwise, just use a default buffer
> >> % size of 4k minus a bit (to give malloc some room).
> >
> > (Unrelated: the buffer size estimation that this comment talks about
> > really only works for the C backend.)
>
> I can see why it could overestimate the size of the buffer needed.
> I don't see how it could underestimate it, and even if it does,
> it should be within one doubling of the correct size, so it should be
> better than starting off with an arbitrary fixed size. Am I wrong?
No, you're right that it will only overestimate the size of the buffer,
by a factor of four in the extreme case (unlikely, of course).
Peter
More information about the reviews
mailing list