Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b92cf06

Browse files
committed
PyObject_CallFunction(), PyObject_CallMethod(): Make sure we do not touch
the va_list until we are sure we have a format string and need to use it; this avoid premature initialization and having to finalize it several different places because of error returns.
1 parent 0af4916 commit b92cf06

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

Objects/abstract.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,20 +1670,18 @@ PyObject_CallFunction(PyObject *callable, char *format, ...)
16701670
{
16711671
va_list va;
16721672
PyObject *args, *retval;
1673-
va_start(va, format);
16741673

1675-
if (callable == NULL) {
1676-
va_end(va);
1674+
if (callable == NULL)
16771675
return null_error();
1678-
}
16791676

1680-
if (format)
1677+
if (format && *format) {
1678+
va_start(va, format);
16811679
args = Py_VaBuildValue(format, va);
1680+
va_end(va);
1681+
}
16821682
else
16831683
args = PyTuple_New(0);
16841684

1685-
va_end(va);
1686-
16871685
if (args == NULL)
16881686
return NULL;
16891687

@@ -1709,32 +1707,27 @@ PyObject_CallMethod(PyObject *o, char *name, char *format, ...)
17091707
{
17101708
va_list va;
17111709
PyObject *args, *func = 0, *retval;
1712-
va_start(va, format);
17131710

1714-
if (o == NULL || name == NULL) {
1715-
va_end(va);
1711+
if (o == NULL || name == NULL)
17161712
return null_error();
1717-
}
17181713

17191714
func = PyObject_GetAttrString(o, name);
17201715
if (func == NULL) {
1721-
va_end(va);
17221716
PyErr_SetString(PyExc_AttributeError, name);
17231717
return 0;
17241718
}
17251719

1726-
if (!PyCallable_Check(func)) {
1727-
va_end(va);
1720+
if (!PyCallable_Check(func))
17281721
return type_error("call of non-callable attribute");
1729-
}
17301722

1731-
if (format && *format)
1723+
if (format && *format) {
1724+
va_start(va, format);
17321725
args = Py_VaBuildValue(format, va);
1726+
va_end(va);
1727+
}
17331728
else
17341729
args = PyTuple_New(0);
17351730

1736-
va_end(va);
1737-
17381731
if (!args)
17391732
return NULL;
17401733

0 commit comments

Comments
 (0)