[m-rev.] for review: Tighten up string.from_code_unit_list et al.
Mark Brown
mark at mercurylang.org
Tue Nov 5 01:29:50 AEDT 2019
Hi Peter,
On Mon, Nov 4, 2019 at 4:51 PM Peter Wang <novalazy at gmail.com> wrote:
>
> library/string.m:
> Document that from_code_unit_list fails if the result string would
> contain a null character, and enforce that in the Java and C#
> implementations. It was already enforced in the C implementation.
>
> Make from_code_unit_list fail if the code unit list contains an
> invalid value (negative or >0xff or >0xffff).
>
> Document that from_utf{8,16}_code_unit_list fail if the result
> string would contain a null character.
s/fail/fails/
> @@ -2027,11 +2034,9 @@ encode_utf16(Char, CodeList0, CodeList) :-
> size = 0;
> list_ptr = CodeList;
> while (! MR_list_is_empty(list_ptr)) {
> - int c;
> - c = MR_list_head(list_ptr);
> - // It is an error to put a null character in a string
> - // (see the comments at the top of this file).
> - if (c == '\\0' || c > 0xff) {
> + unsigned c = (unsigned) MR_list_head(list_ptr);
> + // Check for null character or invalid code unit.
> + if (c == 0 || c > 0xff) {
Well spotted!
Mark
More information about the reviews
mailing list