[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 1/2] tests: Use real size for iov tests
From: |
Juan Quintela |
Subject: |
Re: [Qemu-devel] [PATCH 1/2] tests: Use real size for iov tests |
Date: |
Wed, 30 Aug 2017 13:34:30 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) |
Thomas Huth <address@hidden> wrote:
> On 23.08.2017 10:39, Juan Quintela wrote:
>> We were using -1 instead of the real size because the functions check
>> what is bigger, size in bytes or the size of the iov. Recent gcc's
>> barf at this.
>>
>> Signed-off-by: Juan Quintela <address@hidden>
>> ---
>> tests/test-iov.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> While you're at it, could you maybe also adjust the comments in
> include/qemu/iov.h ? It currently says:
>
> * It is okay to use very large value for `bytes' since we're
> * limited by the size of the iovec anyway, provided that the
> * buffer pointed to by buf has enough space. One possible
> * such "large" value is -1 (sinice size_t is unsigned),
> * so specifying `-1' as `bytes' means 'up to the end of iovec'.
This is for the _full() versions, and still work. the same for
iov_memset().
> ... and apparently -1 is not working anymore as expected. Maybe SIZE_MAX
> from stdint.h is a better choice?
static inline size_t
iov_from_buf(const struct iovec *iov, unsigned int iov_cnt,
size_t offset, const void *buf, size_t bytes)
{
if (__builtin_constant_p(bytes) && iov_cnt &&
offset <= iov[0].iov_len && bytes <= iov[0].iov_len - offset) {
memcpy(iov[0].iov_base + offset, buf, bytes);
return bytes;
} else {
return iov_from_buf_full(iov, iov_cnt, offset, buf, bytes);
}
}
This optimization don't work very well if we used bytes = -1,
furthermore, we return the wrong value.
And no, I don't understand how the (bytes <= iov[0].iov_len - offset)
test pass when bytes == -1.
Later, Juan.
[Qemu-devel] [PATCH 1/2] tests: Use real size for iov tests, Juan Quintela, 2017/08/23