From 9f7446ba568bb737edefaf1a7fe26f218361fd38 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Sat, 19 Apr 2025 17:25:01 +0800 Subject: [PATCH] use allocSentinel (which i didn't know about) --- src/runtime/js.zig | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/runtime/js.zig b/src/runtime/js.zig index 15de61c4..89fd6038 100644 --- a/src/runtime/js.zig +++ b/src/runtime/js.zig @@ -2250,11 +2250,10 @@ fn valueToString(allocator: Allocator, value: v8.Value, isolate: v8.Isolate, con fn valueToStringZ(allocator: Allocator, value: v8.Value, isolate: v8.Isolate, context: v8.Context) ![:0]u8 { const str = try value.toString(context); const len = str.lenUtf8(isolate); - const buf = try allocator.alloc(u8, len + 1); - const n = str.writeUtf8(isolate, buf[0..len]); + const buf = try allocator.allocSentinel(u8, len, 0); + const n = str.writeUtf8(isolate, buf); std.debug.assert(n == len); - buf[len] = 0; - return buf[0..len :0]; + return buf; } const NoopInspector = struct {