mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
std.zig.readSourceFileToEndAlloc: avoid resizing
+1 on the ensure total capacity to account for the fact that we add a null byte before returning. thanks matklad
This commit is contained in:
parent
5784500572
commit
155ab56cc6
@ -536,7 +536,8 @@ pub fn readSourceFileToEndAlloc(gpa: Allocator, file_reader: *std.fs.File.Reader
|
||||
|
||||
if (file_reader.getSize()) |size| {
|
||||
const casted_size = std.math.cast(u32, size) orelse return error.StreamTooLong;
|
||||
try buffer.ensureTotalCapacityPrecise(gpa, casted_size);
|
||||
// +1 to avoid resizing for the null byte added in toOwnedSliceSentinel below.
|
||||
try buffer.ensureTotalCapacityPrecise(gpa, casted_size + 1);
|
||||
} else |_| {}
|
||||
|
||||
try file_reader.interface.appendRemaining(gpa, .@"2", &buffer, .limited(max_src_size));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user