diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-08 07:41:24 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-08 07:41:24 +0000 |
commit | 3483e6dad4f8e795c844d530153d75f29bbf4113 (patch) | |
tree | 98efcfcc00cdf4c58994c80d15c9addcb7122f67 /hash.c | |
parent | 42274ff5860a41f180a356fec2efedf2f313a560 (diff) |
hash.c: +(-1) is a wrong idea
Before this changeset RHASH_ARRAY_SIZE_DEC() was expaneded to include
an expression like `RHASH_ARRAY_SIZE+(-1)`. RHASH_ARRAY_SIZE is by
definition unsigned int. -1 is signed, of course. Adding a signed
and an unsigned value requires the "usual arithmetic conversions" (cf:
ISO/IEC 9899:1990 section 6.2.1.5). -1 is converted to 0xFFFF by that.
This patch prevents that conversion.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65632 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -522,7 +522,11 @@ hash_array_set(VALUE hash, struct li_table *li) } while (0) #define RHASH_ARRAY_SIZE_INC(h) HASH_ARRAY_SIZE_ADD(h, 1) -#define RHASH_ARRAY_SIZE_DEC(h) HASH_ARRAY_SIZE_ADD(h, -1) +#define RHASH_ARRAY_SIZE_DEC(h) do { \ + HASH_ASSERT(RHASH_ARRAY_P(h)); \ + RHASH_ARRAY_SIZE_SET((h), RHASH_ARRAY_SIZE(h) - 1); \ + hash_verify(h); \ +} while (0) #define RHASH_CLEAR_BITS(h) do { \ RBASIC(h)->flags &= ~RHASH_ARRAY_SIZE_MASK; \ |