Skip to content

Commit 3e90fa5

Browse files
committed
Try to cleanup the error handling a bit so there aren't false positives
from static analysis. v was already checked for NULL above, so we don't need a second check.
1 parent 4dc4a84 commit 3e90fa5

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Python/modsupport.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ do_mklist(const char **p_format, va_list *p_va, int endchar, int n)
206206
int itemfailed = 0;
207207
if (n < 0)
208208
return NULL;
209-
if ((v = PyList_New(n)) == NULL)
209+
v = PyList_New(n);
210+
if (v == NULL)
210211
return NULL;
211212
/* Note that we can't bail immediately on error as this will leak
212213
refcounts on any 'N' arguments. */
@@ -219,18 +220,21 @@ do_mklist(const char **p_format, va_list *p_va, int endchar, int n)
219220
}
220221
PyList_SetItem(v, i, w);
221222
}
222-
if (v != NULL && **p_format != endchar) {
223+
224+
if (itemfailed) {
225+
/* do_mkvalue() should have already set an error */
226+
Py_DECREF(v);
227+
return NULL;
228+
}
229+
if (**p_format != endchar) {
223230
Py_DECREF(v);
224-
v = NULL;
225231
PyErr_SetString(PyExc_SystemError,
226232
"Unmatched paren in format");
233+
return NULL;
227234
}
228-
else if (endchar)
235+
236+
if (endchar)
229237
++*p_format;
230-
if (itemfailed) {
231-
Py_DECREF(v);
232-
v = NULL;
233-
}
234238
return v;
235239
}
236240

0 commit comments

Comments
 (0)