Skip to content

Commit b77d9f5

Browse files
authored
Bugfix (#1190)
* posix_file_lock: pass lockp directly to fcntl\n\nBugfix: previously passed address-of pointer variable, causing fcntl to receive an invalid pointer (EFAULT/lock failure). Aligns with POSIX fcntl(fd, cmd, struct flock*). Pure fix. * mfc: fix scatter write loop to use current element (i->base/len)\n\nBugfix: loop used scats->base/len, repeating the first buffer each iteration. Use iterator element to write each scatter segment. * posix_file: copy-assign uses dup when target fd==-1 (unlikely), else dup2\n\nIf target is closed, duplicate source fd; otherwise reuse target via dup2. Avoids dup2(old,-1) failure; no source-closed special-casing.
1 parent c2fe5c9 commit b77d9f5

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

include/fast_io_driver/mfc_impl/mfc_file.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ inline void mfc_scatter_write_impl(CFile *cfp, io_scatter_t const *scats, ::std:
9999
auto e{scats + n};
100100
for (; i != e; ++i)
101101
{
102-
mfc_write_n_impl(cfp, reinterpret_cast<::std::byte const *>(scats->base), scats->len);
102+
mfc_write_n_impl(cfp, reinterpret_cast<::std::byte const *>(i->base), i->len);
103103
}
104104
}
105105

include/fast_io_hosted/platforms/posix.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,14 @@ class basic_posix_family_file : public basic_posix_family_io_observer<family, ch
12731273
{
12741274
return *this;
12751275
}
1276-
this->fd = ::fast_io::details::sys_dup2(dp.fd, this->fd);
1276+
if (this->fd == -1) [[unlikely]]
1277+
{
1278+
this->fd = ::fast_io::details::sys_dup(dp.fd);
1279+
}
1280+
else
1281+
{
1282+
this->fd = ::fast_io::details::sys_dup2(dp.fd, this->fd);
1283+
}
12771284
return *this;
12781285
}
12791286
inline constexpr basic_posix_family_file(basic_posix_family_file &&__restrict b) noexcept

include/fast_io_hosted/platforms/posix_file_lock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace details
66
{
77
inline int fcntl_file_lock(int fd, int cmd, struct flock const *lockp)
88
{
9-
return ::fcntl(fd, cmd, __builtin_addressof(lockp));
9+
return ::fcntl(fd, cmd, lockp);
1010
}
1111

1212
inline void posix_file_lock_lock_common_impl(int fd, struct flock const &lockp)

0 commit comments

Comments
 (0)