Skip to content

Commit a4b48f1

Browse files
ZackerySpytzserhiy-storchaka
authored andcommitted
bpo-34940: Fix the error handling in _check_for_legacy_statements(). (GH-9764)
1 parent 859c068 commit a4b48f1

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Objects/exceptions.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2906,7 +2906,7 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
29062906
*/
29072907
static PyObject *print_prefix = NULL;
29082908
static PyObject *exec_prefix = NULL;
2909-
Py_ssize_t text_len = PyUnicode_GET_LENGTH(self->text);
2909+
Py_ssize_t text_len = PyUnicode_GET_LENGTH(self->text), match;
29102910
int kind = PyUnicode_KIND(self->text);
29112911
void *data = PyUnicode_DATA(self->text);
29122912

@@ -2929,9 +2929,12 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
29292929
return -1;
29302930
}
29312931
}
2932-
if (PyUnicode_Tailmatch(self->text, print_prefix,
2933-
start, text_len, -1)) {
2934-
2932+
match = PyUnicode_Tailmatch(self->text, print_prefix,
2933+
start, text_len, -1);
2934+
if (match == -1) {
2935+
return -1;
2936+
}
2937+
if (match) {
29352938
return _set_legacy_print_statement_msg(self, start);
29362939
}
29372940

@@ -2942,10 +2945,17 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
29422945
return -1;
29432946
}
29442947
}
2945-
if (PyUnicode_Tailmatch(self->text, exec_prefix,
2946-
start, text_len, -1)) {
2947-
Py_XSETREF(self->msg,
2948-
PyUnicode_FromString("Missing parentheses in call to 'exec'"));
2948+
match = PyUnicode_Tailmatch(self->text, exec_prefix, start, text_len, -1);
2949+
if (match == -1) {
2950+
return -1;
2951+
}
2952+
if (match) {
2953+
PyObject *msg = PyUnicode_FromString("Missing parentheses in call "
2954+
"to 'exec'");
2955+
if (msg == NULL) {
2956+
return -1;
2957+
}
2958+
Py_XSETREF(self->msg, msg);
29492959
return 1;
29502960
}
29512961
/* Fall back to the default error message */

0 commit comments

Comments
 (0)