aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorLaurent Vivier <lvivier@redhat.com>2024-03-20 09:47:26 +0100
committerStefano Brivio <sbrivio@redhat.com>2024-03-20 10:06:32 +0100
commit71dd405460b7b1251af9a71aa30c74b7d40da1c3 (patch)
treeac6a7a6ae2b383ccb136293a8179ac027c75e95d
parent639fdf06edecfa0f61eaa55753edb6f3fae9fcef (diff)
downloadpasst-71dd405460b7b1251af9a71aa30c74b7d40da1c3.tar
passt-71dd405460b7b1251af9a71aa30c74b7d40da1c3.tar.gz
passt-71dd405460b7b1251af9a71aa30c74b7d40da1c3.tar.bz2
passt-71dd405460b7b1251af9a71aa30c74b7d40da1c3.tar.lz
passt-71dd405460b7b1251af9a71aa30c74b7d40da1c3.tar.xz
passt-71dd405460b7b1251af9a71aa30c74b7d40da1c3.tar.zst
passt-71dd405460b7b1251af9a71aa30c74b7d40da1c3.zip
util: fix confusion between offset in the iovec array and in the entry2024_03_20.71dd405
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: 8bdb0883b441 ("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>
-rw-r--r--util.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/util.c b/util.c
index 3b2393d..849fa7f 100644
--- a/util.c
+++ b/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 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;
- if (skip) {
- rc = write(fd, (char *)iov[i].iov_base + skip,
- iov[i].iov_len - skip);
+ if (offset) {
+ rc = write(fd, (char *)iov[i].iov_base + offset,
+ iov[i].iov_len - offset);
} else {
rc = writev(fd, &iov[i], iovcnt - i);
}