From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladislav Shpilevoy Subject: [PATCH 04/11] sio: fix passing negative size_t to sio_add_to_iov Date: Fri, 30 Nov 2018 18:39:36 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: tarantool-patches@freelists.org Cc: vdavydov.dev@gmail.com List-ID: sio_add_to_iov moves struct iov position on a specified offset, positive or negative. But its offset argument has size_t type, which is unsigned. Make it be ssize_t. This worked before thanks to how negative numbers are stored. For example, consider uint8_t value = 100; uint8_t offset = -5; Value is stored as 0110 0100. Offset is stored as 1111 1011. (Yes, 1011, not 1010). Sum of the values above is 0001 0101 1111 - first quad overflows and is truncated, so the result is 0101 1111 = 95 - correct. --- src/sio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sio.h b/src/sio.h index ab0a243cd..ff383aa36 100644 --- a/src/sio.h +++ b/src/sio.h @@ -84,7 +84,7 @@ sio_move_iov(struct iovec *iov, size_t nwr, size_t *iov_len) * to adjust to a partial write. */ static inline void -sio_add_to_iov(struct iovec *iov, size_t size) +sio_add_to_iov(struct iovec *iov, ssize_t size) { iov->iov_len += size; iov->iov_base = (char *) iov->iov_base - size; -- 2.17.2 (Apple Git-113)