From f9ba2efe1e60fa919b0efe70994416149b54ee26 Mon Sep 17 00:00:00 2001 From: Emmanuel Leblond Date: Sat, 1 Feb 2020 07:04:14 +0100 Subject: Modify Dictionary::operator== to do real key/value comparison with recursive support (and add unittests) --- core/templates/ordered_hash_map.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'core/templates') diff --git a/core/templates/ordered_hash_map.h b/core/templates/ordered_hash_map.h index 7a17eeb644..4996b88190 100644 --- a/core/templates/ordered_hash_map.h +++ b/core/templates/ordered_hash_map.h @@ -207,8 +207,12 @@ public: (*list_element)->get().second = p_value; return Element(*list_element); } - typename InternalList::Element *new_element = list.push_back(Pair(nullptr, p_value)); + // Incorrectly set the first value of the pair with a value that will + // be invalid as soon as we leave this function... + typename InternalList::Element *new_element = list.push_back(Pair(&p_key, p_value)); + // ...this is needed here in case the hashmap recursively reference itself... typename InternalMap::Element *e = map.set(p_key, new_element); + // ...now we can set the right value ! new_element->get().first = &e->key(); return Element(new_element); -- cgit v1.2.3