authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-11-26 19:33:42+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-26 14:35:46-08:00
logb196dd1d7958aee86095bd06190eee484a562488
tree43265d5c3ef346f57a041c107b9529880d4cac53
parent7c2cc45ad87b621831ac4b8cada809c2d88cdf0d

std.system: fix slice bounds in preadMin()

If a partial read occurs past the halfway point, buf.len - i will be less than i, which is illegal. The end bound is also entirely unecessary in this case, so just remove it.

1 files changed, 1 insertions(+), 1 deletions(-)

lib/std/zig/system.zig+1-1
......@@ -922,7 +922,7 @@ pub const NativeTargetInfo = struct {
922922 fn preadMin(file: fs.File, buf: []u8, offset: u64, min_read_len: usize) !usize {
923923 var i: usize = 0;
924924 while (i < min_read_len) {
925 const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) {
925 const len = file.pread(buf[i..], offset + i) catch |err| switch (err) {
926926 error.OperationAborted => unreachable, // Windows-only
927927 error.WouldBlock => unreachable, // Did not request blocking mode
928928 error.NotOpenForReading => unreachable,