From f19ed6b0c77ba3bdaa1d8c304a61f2fa90b5d6ac Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Mon, 22 Jun 2020 01:01:48 -0700 Subject: bpo-41061: Fix incorrect expressions in hashtable (GH-21028) Signed-off-by: Christian Heimes (cherry picked from commit 4901ea952691ad70aae21cfe04b6bd363b5a6aff) Co-authored-by: Christian Heimes --- .../next/Core and Builtins/2020-06-21-10-54-02.bpo-41061.AHf9MU.rst | 1 + Modules/_testinternalcapi.c | 4 ++-- Python/hashtable.c | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2020-06-21-10-54-02.bpo-41061.AHf9MU.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-21-10-54-02.bpo-41061.AHf9MU.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-21-10-54-02.bpo-41061.AHf9MU.rst new file mode 100644 index 0000000..b5bb816 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-06-21-10-54-02.bpo-41061.AHf9MU.rst @@ -0,0 +1 @@ +Fix incorrect expressions and asserts in hashtable code and tests. diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c index 5f217dc..8faa9fe 100644 --- a/Modules/_testinternalcapi.c +++ b/Modules/_testinternalcapi.c @@ -119,8 +119,8 @@ test_hashtable(PyObject *self, PyObject *Py_UNUSED(args)) for (key='a'; key <= 'z'; key++) { _Py_hashtable_entry_t *entry = _Py_hashtable_get_entry(table, TO_PTR(key)); assert(entry != NULL); - assert(entry->key = TO_PTR(key)); - assert(entry->value = TO_PTR(VALUE(key))); + assert(entry->key == TO_PTR(key)); + assert(entry->value == TO_PTR(VALUE(key))); } // Test _Py_hashtable_get() diff --git a/Python/hashtable.c b/Python/hashtable.c index b92e8ca..09501de 100644 --- a/Python/hashtable.c +++ b/Python/hashtable.c @@ -133,7 +133,7 @@ _Py_hashtable_get_entry_generic(_Py_hashtable_t *ht, const void *key) { Py_uhash_t key_hash = ht->hash_func(key); size_t index = key_hash & (ht->nbuckets - 1); - _Py_hashtable_entry_t *entry = entry = TABLE_HEAD(ht, index); + _Py_hashtable_entry_t *entry = TABLE_HEAD(ht, index); while (1) { if (entry == NULL) { return NULL; @@ -155,7 +155,7 @@ _Py_hashtable_get_entry_ptr(_Py_hashtable_t *ht, const void *key) { Py_uhash_t key_hash = _Py_hashtable_hash_ptr(key); size_t index = key_hash & (ht->nbuckets - 1); - _Py_hashtable_entry_t *entry = entry = TABLE_HEAD(ht, index); + _Py_hashtable_entry_t *entry = TABLE_HEAD(ht, index); while (1) { if (entry == NULL) { return NULL; -- cgit v0.12