Skip to content

Commit b196dd1

Browse files
ifreundandrewrk
authored andcommitted
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 parent 7c2cc45 commit b196dd1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/std/zig/system.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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,

0 commit comments

Comments
 (0)