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
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 pread(fd, buf!, nbyte, offset)
}

// 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 pwrite(fd, buf!, nbyte, offset)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid we can't do it this way. This pointer comes from a caller-supplied buffer, whose baseAddress could well be nil. For example:

    let fd = FileDescriptor.standardOutput
    let empty = UnsafeRawBufferPointer(start: nil, count: 0)
    let written = try fd.write(toAbsoluteOffset: 0, empty) // crash at runtime with the suggested force-unwrap

We don't have that precise case covered in a test, but we should!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will check it instead.

}

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