mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
42274ff586
commit
3483e6dad4
1 changed files with 5 additions and 1 deletions
6
hash.c
6
hash.c
|
@ -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; \
|
||||
|
|
Loading…
Reference in a new issue