mirror of
https://passt.top/passt
synced 2024-12-22 13:45:32 +00:00
util: fix confusion between offset in the iovec array and in the entry
In write_remainder() 'skip' is the offset to start the operation from
in the iovec array.
In iov_skip_bytes(), 'skip' is also the offset in the iovec array but
'offset' is the first unskipped byte in the iovec entry.
As write_remainder() uses 'skip' for both, 'skip' is reset to the
first unskipped byte in the iovec entry rather to staying the first
unskipped byte in the iovec array.
Fix the problem by introducing a new variable not to overwrite 'skip'
on each loop.
Fixes: 8bdb0883b4
("util: Add write_remainder() helper")
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
639fdf06ed
commit
71dd405460
9
util.c
9
util.c
@ -533,13 +533,14 @@ int do_clone(int (*fn)(void *), char *stack_area, size_t stack_size, int flags,
|
|||||||
int write_remainder(int fd, const struct iovec *iov, int iovcnt, size_t skip)
|
int write_remainder(int fd, const struct iovec *iov, int iovcnt, size_t skip)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
size_t offset;
|
||||||
|
|
||||||
while ((i = iov_skip_bytes(iov, iovcnt, skip, &skip)) < iovcnt) {
|
while ((i = iov_skip_bytes(iov, iovcnt, skip, &offset)) < iovcnt) {
|
||||||
ssize_t rc;
|
ssize_t rc;
|
||||||
|
|
||||||
if (skip) {
|
if (offset) {
|
||||||
rc = write(fd, (char *)iov[i].iov_base + skip,
|
rc = write(fd, (char *)iov[i].iov_base + offset,
|
||||||
iov[i].iov_len - skip);
|
iov[i].iov_len - offset);
|
||||||
} else {
|
} else {
|
||||||
rc = writev(fd, &iov[i], iovcnt - i);
|
rc = writev(fd, &iov[i], iovcnt - i);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user