[issue8420] Objects/setobject.c contains unsafe code

Éric Araujo report at bugs.python.org
Wed Mar 23 01:20:49 CET 2011


Éric Araujo <merwok at netwok.org> added the comment:

Here is a part of my 3.1 patch:

+    PyObject *key = entry->key;
+    long hash = entry->hash;

     assert(so->fill <= so->mask);  /* at least one empty slot */
     n_used = so->used;
-    Py_INCREF(entry->key);
-    if (set_insert_key(so, entry->key, (long) entry->hash) == -1) {
-        Py_DECREF(entry->key);
+    Py_INCREF(key);
+    if (set_insert_key(so, key, hash) == -1) {
+        Py_DECREF(key);

You’ll notice that I declare hash as long, but I don’t need to cast it to long to make it compile and run.  However, the previous code did cast; was that done on purpose, maybe for 32-bit platforms, or is it okay to not have the cast?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8420>
_______________________________________


More information about the Python-bugs-list mailing list