We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b01d6b1 commit c0d85cdCopy full SHA for c0d85cd
lib/std/fs/File.zig
@@ -1156,7 +1156,7 @@ pub fn readToEndAllocOptions(
1156
// The file size returned by stat is used as hint to set the buffer
1157
// size. If the reported size is zero, as it happens on Linux for files
1158
// in /proc, a small buffer is allocated instead.
1159
- 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);
1160
var array_list = try std.ArrayListAligned(u8, alignment).initCapacity(allocator, initial_cap);
1161
defer array_list.deinit();
1162
0 commit comments