Skip to content

Commit 3483e6d

Browse files
committed
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
1 parent 42274ff commit 3483e6d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

hash.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,11 @@ hash_array_set(VALUE hash, struct li_table *li)
522522
} while (0)
523523

524524
#define RHASH_ARRAY_SIZE_INC(h) HASH_ARRAY_SIZE_ADD(h, 1)
525-
#define RHASH_ARRAY_SIZE_DEC(h) HASH_ARRAY_SIZE_ADD(h, -1)
525+
#define RHASH_ARRAY_SIZE_DEC(h) do { \
526+
HASH_ASSERT(RHASH_ARRAY_P(h)); \
527+
RHASH_ARRAY_SIZE_SET((h), RHASH_ARRAY_SIZE(h) - 1); \
528+
hash_verify(h); \
529+
} while (0)
526530

527531
#define RHASH_CLEAR_BITS(h) do { \
528532
RBASIC(h)->flags &= ~RHASH_ARRAY_SIZE_MASK; \

0 commit comments

Comments
 (0)