Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: tarantool-patches@freelists.org
Subject: Re: [PATCH 04/11] sio: fix passing negative size_t to sio_add_to_iov
Date: Wed, 5 Dec 2018 00:29:20 +0300	[thread overview]
Message-ID: <747f4d88-4913-d99d-ee7f-0b9ca994258a@tarantool.org> (raw)
In-Reply-To: <20181203135003.beibxo7vwnwiam2m@esperanza>



On 03/12/2018 16:50, Vladimir Davydov wrote:
> On Fri, Nov 30, 2018 at 06:39:36PM +0300, Vladislav Shpilevoy wrote:
>> 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_len' has type size_t so 'size' will be converted to size_t before
> the operation, in other words this patch has, in fact, no effect.

It fixes corrupted logic - you should not accept negative numbers in
positive types. Even if they are the same internally.

> 
> Anyway, it's OK to apply unary minus to an unsigned variable: no matter
> how integer types are stored, whether the machine uses two's-complement
> or not, it should work so that (-x + x) equals 0.

I do not argue with it. But then why do we have signed types? Lets use
unsigned everywhere (<sarcasm>).

It does not matter does a compiler allow to turn a number into
the complement or not. Logic of storing negative numbers in
positive types is corrupted by definition.

> 
> That being said, I don't think we need this patch.
> 

As you wish. Removed in v2.

  reply	other threads:[~2018-12-04 21:29 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-30 15:39 [PATCH 00/11] SWIM preparation Vladislav Shpilevoy
2018-11-30 15:39 ` [PATCH 01/11] box: move info_handler interface into src/info Vladislav Shpilevoy
2018-12-03 11:05   ` Vladimir Davydov
2018-12-03 21:48     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-03 20:41   ` [tarantool-patches] " Konstantin Osipov
2018-12-03 21:48     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-04  8:52       ` Vladimir Davydov
2018-11-30 15:39 ` [PATCH 10/11] evio: remove exceptions Vladislav Shpilevoy
2018-11-30 15:39 ` [PATCH 11/11] evio: turn into C Vladislav Shpilevoy
2018-11-30 15:39 ` [PATCH 02/11] sio: remove unused functions, restyle code Vladislav Shpilevoy
2018-12-03 12:28   ` Vladimir Davydov
2018-12-04 21:29     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-05  8:41       ` Vladimir Davydov
2018-11-30 15:39 ` [PATCH 03/11] sio: remove exceptions Vladislav Shpilevoy
2018-12-03 12:36   ` Vladimir Davydov
2018-12-04 21:29     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-05  8:42       ` Vladimir Davydov
2018-11-30 15:39 ` [PATCH 04/11] sio: fix passing negative size_t to sio_add_to_iov Vladislav Shpilevoy
2018-12-03 13:50   ` Vladimir Davydov
2018-12-04 21:29     ` Vladislav Shpilevoy [this message]
2018-12-05  8:48       ` Vladimir Davydov
2018-11-30 15:39 ` [PATCH 05/11] sio: turn into C Vladislav Shpilevoy
2018-11-30 15:39 ` [PATCH 06/11] evio: make on_accept be nothrow Vladislav Shpilevoy
2018-12-03 14:58   ` Vladimir Davydov
2018-12-04 21:29     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-05  8:52       ` Vladimir Davydov
2018-11-30 15:39 ` [PATCH 07/11] coio: fix file descriptor leak on accept Vladislav Shpilevoy
2018-12-03 16:16   ` Vladimir Davydov
2018-12-04 21:29     ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-30 15:39 ` [PATCH 08/11] coio: fix double close of a file descriptor Vladislav Shpilevoy
2018-12-03 16:19   ` Vladimir Davydov
2018-12-04 21:29     ` [tarantool-patches] " Vladislav Shpilevoy
2018-11-30 15:39 ` [PATCH 09/11] evio: refactoring Vladislav Shpilevoy
2018-12-03 16:37   ` Vladimir Davydov
2018-12-04 21:29     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-03  9:47 ` [PATCH 00/11] SWIM preparation Vladimir Davydov
2018-12-03 10:27   ` [tarantool-patches] " Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=747f4d88-4913-d99d-ee7f-0b9ca994258a@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH 04/11] sio: fix passing negative size_t to sio_add_to_iov' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox