diff options
| author | Rui He <118280419+ruihe774@users.noreply.github.com> | 2025-01-30 23:42:15 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-30 16:42:15 +0100 |
| commit | c0d85cda53fd9ea056641d5e91cc8f736b34c0e7 (patch) | |
| tree | 1cab079ea3504484aea45e6fb1813b36fc3e0060 /lib/std/fs/File.zig | |
| parent | b01d6b156cf4d273be40a6e6288f4766f71f4a29 (diff) | |
| download | zig-c0d85cda53fd9ea056641d5e91cc8f736b34c0e7.tar.gz zig-c0d85cda53fd9ea056641d5e91cc8f736b34c0e7.zip | |
std.fs.File: limit initial_cap according to max_bytes in readToEndAllocOptions
Diffstat (limited to 'lib/std/fs/File.zig')
| -rw-r--r-- | lib/std/fs/File.zig | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/std/fs/File.zig b/lib/std/fs/File.zig index 69c3553ac3..9797a1b896 100644 --- a/lib/std/fs/File.zig +++ b/lib/std/fs/File.zig @@ -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(); |
