Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
avoid passing null pointer to pread() or pwrite()
  • Loading branch information
glessard committed Jan 5, 2024
commit c2e8f24c7c81c1842af8a556f7940abf96ec3a5f
4 changes: 2 additions & 2 deletions Sources/System/Internals/Syscalls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ internal func system_pread(
#if ENABLE_MOCKING
if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) }
#endif
return pread(fd, buf!, nbyte, offset)
return buf.map({ pread(fd, $0, nbyte, offset) }) ?? 0
}

// lseek
Expand Down Expand Up @@ -101,7 +101,7 @@ internal func system_pwrite(
#if ENABLE_MOCKING
if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) }
#endif
return pwrite(fd, buf!, nbyte, offset)
return buf.map({ pwrite(fd, $0, nbyte, offset) }) ?? 0
}

internal func system_dup(_ fd: Int32) -> Int32 {
Expand Down