Skip to content

Commit

Permalink
std.system: fix slice bounds in preadMin()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ifreund authored and andrewrk committed Nov 26, 2021
1 parent 7c2cc45 commit b196dd1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/std/zig/system.zig
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ pub const NativeTargetInfo = struct {
fn preadMin(file: fs.File, buf: []u8, offset: u64, min_read_len: usize) !usize {
var i: usize = 0;
while (i < min_read_len) {
const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) {
const len = file.pread(buf[i..], offset + i) catch |err| switch (err) {
error.OperationAborted => unreachable, // Windows-only
error.WouldBlock => unreachable, // Did not request blocking mode
error.NotOpenForReading => unreachable,
Expand Down

0 comments on commit b196dd1

Please sign in to comment.