encoding/utf8: enforce scalar and buffer bounds

This commit is contained in:
2026-08-09 17:39:41 +09:00
parent 83101add2c
commit 8620e64313
4 changed files with 57 additions and 7 deletions

View File

@@ -4,6 +4,7 @@
package utf8_test;
import encoding.utf8;
import test;
// ref/hare/encoding/utf8/encode.ha:7. Byte vectors come from the
// Unicode specification (UAX standard examples).
@@ -41,3 +42,11 @@ import encoding.utf8;
assert(!(out[2] != 0xA6u8));
assert(!(out[3] != 0x80u8));
};
// The ww API writes into caller storage, unlike Hare's static-buffer return.
// A short slice must fail before the first out-of-bounds store.
@test fn encode_short_buffer_aborts() void = {
test.expectabort();
let out: [1]u8;
utf8.encoderune(out[0:1], 0xE9u32: rune);
};