summaryrefslogtreecommitdiff
path: root/Modules/mathmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-22 14:22:22 +0100
committerGitHub <noreply@github.com>2022-11-22 14:22:22 +0100
commit7e3f09cad9b783d8968aa79ff6a8ee57beb8b83e (patch)
treea8d4dda9e9128545442794595f5ebc96a5c1c7b4 /Modules/mathmodule.c
parent135ec7cefbaffd516b77362ad2b2ad1025af462e (diff)
downloadcpython-git-7e3f09cad9b783d8968aa79ff6a8ee57beb8b83e.tar.gz
gh-99537: Use Py_SETREF() function in C code (#99656)
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 'Modules/mathmodule.c')
-rw-r--r--Modules/mathmodule.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 16a2f45c8b..83eb338be9 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -2069,8 +2069,7 @@ factorial_odd_part(unsigned long n)
Py_DECREF(partial);
if (tmp == NULL)
goto error;
- Py_DECREF(inner);
- inner = tmp;
+ Py_SETREF(inner, tmp);
/* Now inner is the product of all odd integers j in the range (0,
n/2**i], giving the inner product in the formula above. */
@@ -2078,8 +2077,7 @@ factorial_odd_part(unsigned long n)
tmp = PyNumber_Multiply(outer, inner);
if (tmp == NULL)
goto error;
- Py_DECREF(outer);
- outer = tmp;
+ Py_SETREF(outer, tmp);
}
Py_DECREF(inner);
return outer;