From ea74da0c6c71edf8025ff67fbf445251d512acf1 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 6 Jul 2014 14:42:57 +0000 Subject: st.c: re-calc hash_val before adding * st.c (st_update): re-calculate hash_val before adding if key was changed, otherwise cannot access the newly added element if it has different hash value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- st.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'st.c') diff --git a/st.c b/st.c index 1d78ffebad..117f582703 100644 --- a/st.c +++ b/st.c @@ -843,6 +843,7 @@ st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data switch (retval) { case ST_CONTINUE: if (!existing) { + if (key != old_key) hash_val = do_hash(key, table); add_packed_direct(table, key, value, hash_val); break; } @@ -878,6 +879,7 @@ st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data switch (retval) { case ST_CONTINUE: if (!existing) { + if (key != old_key) hash_val = do_hash(key, table); add_direct(table, key, value, hash_val, hash_pos(hash_val, table->num_bins)); break; } -- cgit v1.2.3