ruby-changes:53416
From: shyouhei <ko1@a...>
Date: Thu, 8 Nov 2018 16:41:30 +0900 (JST)
Subject: [ruby-changes:53416] shyouhei:r65632 (trunk): hash.c: +(-1) is a wrong idea
shyouhei 2018-11-08 16:41:24 +0900 (Thu, 08 Nov 2018) New Revision: 65632 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65632 Log: 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. Modified files: trunk/hash.c Index: hash.c =================================================================== --- hash.c (revision 65631) +++ hash.c (revision 65632) @@ -522,7 +522,11 @@ hash_array_set(VALUE hash, struct li_tab https://github.com/ruby/ruby/blob/trunk/hash.c#L522 } 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; \ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/