summaryrefslogtreecommitdiffstats
path: root/Objects/stringlib
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-22 12:39:11 (GMT)
committerGitHub <noreply@github.com>2022-11-22 12:39:11 (GMT)
commit135ec7cefbaffd516b77362ad2b2ad1025af462e (patch)
tree1f92fbda32d21f0efc9f54432c32af03fe49a608 /Objects/stringlib
parent3db0a21f731cec28a89f7495a82ee2670bce75fe (diff)
downloadcpython-135ec7cefbaffd516b77362ad2b2ad1025af462e.zip
cpython-135ec7cefbaffd516b77362ad2b2ad1025af462e.tar.gz
cpython-135ec7cefbaffd516b77362ad2b2ad1025af462e.tar.bz2
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/stringlib')
-rw-r--r--Objects/stringlib/unicode_format.h6
1 files changed, 2 insertions, 4 deletions
diff --git a/Objects/stringlib/unicode_format.h b/Objects/stringlib/unicode_format.h
index e970588..ccd7c77 100644
--- a/Objects/stringlib/unicode_format.h
+++ b/Objects/stringlib/unicode_format.h
@@ -473,8 +473,7 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs,
goto error;
/* assign to obj */
- Py_DECREF(obj);
- obj = tmp;
+ Py_SETREF(obj, tmp);
}
/* end of iterator, this is the non-error case */
if (ok == 1)
@@ -825,8 +824,7 @@ output_markup(SubString *field_name, SubString *format_spec,
goto done;
/* do the assignment, transferring ownership: fieldobj = tmp */
- Py_DECREF(fieldobj);
- fieldobj = tmp;
+ Py_SETREF(fieldobj, tmp);
tmp = NULL;
}