Skip to contentSkip to conversation

util: Fix assertion in iov_copy() upon zero 'bytes' and non-zero 'offset'

PATCH New Shmulik Ladkani 1 participant 1 message Aug 2, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 util: Fix assertion in iov_copy() upon zero 'bytes' and non-zero 'offset'

From: Shmulik Ladkani <[email protected]>

In cases where iov_copy() is passed with zero 'bytes' argument and a non-zero 'offset' argument, nothing gets copied - as expected.

However no copy iterations are performed, so 'offset' is left unaltered, leading to the final assert(offset == 0) to fail.

Instead, change the loop condition to continue as long as 'offset || bytes', similar to other iov_* functions.

This ensures 'offset' gets zeroed (even if no actual copy is made), unless it is beyond end of source iov - which is asserted.

---
 util/iov.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

v2: Instead of relaxing the assertion, modify loop condition,
as suggested by Paolo

util/iov.c +2 -1
index 003fcce..74e6ca8 100644
@@ -247,7 +247,8 @@ unsigned iov_copy(struct iovec *dst_iov, unsigned int dst_iov_cnt,
 {
     size_t len;
     unsigned int i, j;
-    for (i = 0, j = 0; i < iov_cnt && j < dst_iov_cnt && bytes; i++) {
+    for (i = 0, j = 0;
+         i < iov_cnt && j < dst_iov_cnt && (offset || bytes); i++) {
         if (offset >= iov[i].iov_len) {
             offset -= iov[i].iov_len;
             continue;
Signature · 1 line
1.9.1