diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-10-13 12:25:59 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-10-13 12:25:59 -0400 |
| commit | 5a26b365fc732c0873474371880b43fc9e843e4b (patch) | |
| tree | 684643c635f735480e4b07f8cafc52747dc80878 | |
| parent | 31b22c9b54d33a8ab55f9e1f46d13231c9e974e7 (diff) | |
Minor speculative fixes to be extra cautious
| -rw-r--r-- | src/stdlib/text.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/stdlib/text.c b/src/stdlib/text.c index a91490e6..c79f20cc 100644 --- a/src/stdlib/text.c +++ b/src/stdlib/text.c @@ -730,6 +730,7 @@ PUREFUNC OptionalText_t Text$cluster(Text_t text, Int_t index) { } static Text_t Text$from_components(List_t graphemes, Table_t unique_clusters) { + if (graphemes.length == 0) return EMPTY_TEXT; size_t blob_size = (sizeof(int32_t[unique_clusters.entries.length]) + sizeof(uint8_t[graphemes.length])); // If blob optimization will save at least 200 bytes: if (unique_clusters.entries.length <= 256 && blob_size + 200 < sizeof(int32_t[graphemes.length])) { @@ -1569,6 +1570,7 @@ public List_t Text$utf16(Text_t text) { if (text.length == 0) return EMPTY_ATOMIC_LIST; List_t utf32 = Text$utf32(text); + if (utf32.length == 0) return EMPTY_ATOMIC_LIST; List_t utf16 = {.free = MIN(LIST_MAX_FREE_ENTRIES, (uint64_t)utf32.length), .atomic = 1}; utf16.data = GC_MALLOC_ATOMIC(sizeof(int32_t[utf16.free])); for (int64_t i = 0; i < (int64_t)utf32.length; i++) { |
