Skip to content

Commit 9f7446b

Browse files
committed
use allocSentinel (which i didn't know about)
1 parent 7bdea1b commit 9f7446b

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/runtime/js.zig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,11 +2250,10 @@ fn valueToString(allocator: Allocator, value: v8.Value, isolate: v8.Isolate, con
22502250
fn valueToStringZ(allocator: Allocator, value: v8.Value, isolate: v8.Isolate, context: v8.Context) ![:0]u8 {
22512251
const str = try value.toString(context);
22522252
const len = str.lenUtf8(isolate);
2253-
const buf = try allocator.alloc(u8, len + 1);
2254-
const n = str.writeUtf8(isolate, buf[0..len]);
2253+
const buf = try allocator.allocSentinel(u8, len, 0);
2254+
const n = str.writeUtf8(isolate, buf);
22552255
std.debug.assert(n == len);
2256-
buf[len] = 0;
2257-
return buf[0..len :0];
2256+
return buf;
22582257
}
22592258

22602259
const NoopInspector = struct {

0 commit comments

Comments
 (0)