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

Skip to content

Commit 9da7f3b

Browse files
committed
SyntaxError__init__(): Be a little more robust when picking apart the
location information for the SyntaxError -- do not do more than we need to, stopping as soon as an exception has been raised.
1 parent 9c98a42 commit 9da7f3b

1 file changed

Lines changed: 22 additions & 16 deletions

File tree

Python/exceptions.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -702,29 +702,35 @@ SyntaxError__init__(PyObject *self, PyObject *args)
702702
}
703703
if (lenargs == 2) {
704704
PyObject *info = PySequence_GetItem(args, 1);
705-
PyObject *filename, *lineno, *offset, *text;
705+
PyObject *filename = NULL, *lineno = NULL;
706+
PyObject *offset = NULL, *text = NULL;
706707
int status = 1;
707708

708709
if (!info)
709710
goto finally;
710711

711712
filename = PySequence_GetItem(info, 0);
712-
lineno = PySequence_GetItem(info, 1);
713-
offset = PySequence_GetItem(info, 2);
714-
text = PySequence_GetItem(info, 3);
715-
716-
Py_DECREF(info);
717-
718-
if (filename && lineno && offset && text) {
719-
status = PyObject_SetAttrString(self, "filename", filename) ||
720-
PyObject_SetAttrString(self, "lineno", lineno) ||
721-
PyObject_SetAttrString(self, "offset", offset) ||
722-
PyObject_SetAttrString(self, "text", text);
713+
if (filename != NULL) {
714+
lineno = PySequence_GetItem(info, 1);
715+
if (lineno != NULL) {
716+
offset = PySequence_GetItem(info, 2);
717+
if (offset != NULL) {
718+
text = PySequence_GetItem(info, 3);
719+
if (text != NULL) {
720+
status =
721+
PyObject_SetAttrString(self, "filename", filename)
722+
|| PyObject_SetAttrString(self, "lineno", lineno)
723+
|| PyObject_SetAttrString(self, "offset", offset)
724+
|| PyObject_SetAttrString(self, "text", text);
725+
Py_DECREF(text);
726+
}
727+
Py_DECREF(offset);
728+
}
729+
Py_DECREF(lineno);
730+
}
731+
Py_DECREF(filename);
723732
}
724-
Py_XDECREF(filename);
725-
Py_XDECREF(lineno);
726-
Py_XDECREF(offset);
727-
Py_XDECREF(text);
733+
Py_DECREF(info);
728734

729735
if (status)
730736
goto finally;

0 commit comments

Comments
 (0)