mirror of
https://github.com/ziglang/zig.git
synced 2025-12-29 17:43:17 +00:00
std.fs.File: limit initial_cap according to max_bytes in readToEndAllocOptions
This commit is contained in:
parent
b01d6b156c
commit
c0d85cda53
@ -1156,7 +1156,7 @@ pub fn readToEndAllocOptions(
|
||||
// The file size returned by stat is used as hint to set the buffer
|
||||
// size. If the reported size is zero, as it happens on Linux for files
|
||||
// in /proc, a small buffer is allocated instead.
|
||||
const initial_cap = (if (size > 0) size else 1024) + @intFromBool(optional_sentinel != null);
|
||||
const initial_cap = @min((if (size > 0) size else 1024), max_bytes) + @intFromBool(optional_sentinel != null);
|
||||
var array_list = try std.ArrayListAligned(u8, alignment).initCapacity(allocator, initial_cap);
|
||||
defer array_list.deinit();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user