From 450b066cb812ebb69da111de6dd7aa00774266b4 Mon Sep 17 00:00:00 2001 From: dave caruso Date: Tue, 8 Aug 2023 22:27:18 -0700 Subject: Fix one of the astro segfaults, also fix bun init version (#4079) * 4->16 * add assertions * fix version stuff --- src/string_immutable.zig | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/string_immutable.zig') diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 3aaec1314..fd5bcb00a 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -1480,9 +1480,12 @@ pub fn convertUTF16ToUTF8(list_: std.ArrayList(u8), comptime Type: type, utf16: pub fn toUTF8AllocWithType(allocator: std.mem.Allocator, comptime Type: type, utf16: Type) ![]u8 { if (bun.FeatureFlags.use_simdutf and comptime Type == []const u16) { const length = bun.simdutf.length.utf8.from.utf16.le(utf16); - // add 4 bytes of padding for SIMDUTF - var list = try std.ArrayList(u8).initCapacity(allocator, length + 4); + // add 16 bytes of padding for SIMDUTF + var list = try std.ArrayList(u8).initCapacity(allocator, length + 16); list = try convertUTF16ToUTF8(list, Type, utf16); + if (Environment.allow_assert) { + std.debug.assert(list.items.len == length); + } return list.items; } @@ -1496,7 +1499,11 @@ pub fn toUTF8ListWithType(list_: std.ArrayList(u8), comptime Type: type, utf16: var list = list_; const length = bun.simdutf.length.utf8.from.utf16.le(utf16); try list.ensureTotalCapacityPrecise(length + 16); - return convertUTF16ToUTF8(list, Type, utf16); + const buf = try convertUTF16ToUTF8(list, Type, utf16); + if (Environment.allow_assert) { + std.debug.assert(buf.items.len == length); + } + return buf; } return toUTF8ListWithTypeBun(list_, Type, utf16); -- cgit v1.2.3