summaryrefslogtreecommitdiff
path: root/src/libstddjb
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb')
-rw-r--r--src/libstddjb/siovec_trunc.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/libstddjb/siovec_trunc.c b/src/libstddjb/siovec_trunc.c
index d71f9d9..621e55f 100644
--- a/src/libstddjb/siovec_trunc.c
+++ b/src/libstddjb/siovec_trunc.c
@@ -6,13 +6,13 @@
unsigned int siovec_trunc (struct iovec *v, unsigned int n, size_t len)
{
size_t w = siovec_len(v, n) ;
- unsigned int i = n ;
if (w < len) return n ;
len = w - len ;
- while (len && i--)
+ while (n && len)
{
- w = len > v[i].iov_len ? v[i].iov_len : len ;
- v[i].iov_len -= w ; len -= w ;
+ w = len > v[n-1].iov_len ? v[n-1].iov_len : len ;
+ v[n-1].iov_len -= w ; len -= w ;
+ if (!v[n-1].iov_len) n-- ;
}
- return i ;
+ return n ;
}