[m-rev.] for post-commit review: fix NumCodeUnits != FileStringLen aborts in C#

Zoltan Somogyi zoltan.somogyi at runbox.com
Fri Mar 11 13:15:56 AEDT 2022


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?

> The file may not necessarily contain (valid) UTF-8 so it would be more
> fair to say that it counts "bytes".

OK, I will reword that, and follow your other suggestions, once I am done
with the change I am now making to io.m.

Zoltan.


More information about the reviews mailing list