diff options
author | Victor Stinner <vstinner@python.org> | 2022-11-22 13:39:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-22 13:39:11 +0100 |
commit | 135ec7cefbaffd516b77362ad2b2ad1025af462e (patch) | |
tree | 1f92fbda32d21f0efc9f54432c32af03fe49a608 /Objects/floatobject.c | |
parent | 3db0a21f731cec28a89f7495a82ee2670bce75fe (diff) | |
download | cpython-git-135ec7cefbaffd516b77362ad2b2ad1025af462e.tar.gz |
gh-99537: Use Py_SETREF() function in C code (#99657)
Fix potential race condition in code patterns:
* Replace "Py_DECREF(var); var = new;" with "Py_SETREF(var, new);"
* Replace "Py_XDECREF(var); var = new;" with "Py_XSETREF(var, new);"
* Replace "Py_CLEAR(var); var = new;" with "Py_XSETREF(var, new);"
Other changes:
* Replace "old = var; var = new; Py_DECREF(var)"
with "Py_SETREF(var, new);"
* Replace "old = var; var = new; Py_XDECREF(var)"
with "Py_XSETREF(var, new);"
* And remove the "old" variable.
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r-- | Objects/floatobject.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 46016e946a..912b742f79 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -531,20 +531,17 @@ float_richcompare(PyObject *v, PyObject *w, int op) temp = _PyLong_Lshift(ww, 1); if (temp == NULL) goto Error; - Py_DECREF(ww); - ww = temp; + Py_SETREF(ww, temp); temp = _PyLong_Lshift(vv, 1); if (temp == NULL) goto Error; - Py_DECREF(vv); - vv = temp; + Py_SETREF(vv, temp); temp = PyNumber_Or(vv, _PyLong_GetOne()); if (temp == NULL) goto Error; - Py_DECREF(vv); - vv = temp; + Py_SETREF(vv, temp); } r = PyObject_RichCompareBool(vv, ww, op); |