Skip to content

bpo-34940: Fix the error handling in _check_for_legacy_statements() #9764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2906,7 +2906,7 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
*/
static PyObject *print_prefix = NULL;
static PyObject *exec_prefix = NULL;
Py_ssize_t text_len = PyUnicode_GET_LENGTH(self->text);
Py_ssize_t text_len = PyUnicode_GET_LENGTH(self->text), match;
int kind = PyUnicode_KIND(self->text);
void *data = PyUnicode_DATA(self->text);

Expand All @@ -2929,9 +2929,12 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
return -1;
}
}
if (PyUnicode_Tailmatch(self->text, print_prefix,
start, text_len, -1)) {

match = PyUnicode_Tailmatch(self->text, print_prefix,
start, text_len, -1);
if (match == -1) {
return -1;
}
if (match) {
return _set_legacy_print_statement_msg(self, start);
}

Expand All @@ -2942,10 +2945,17 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
return -1;
}
}
if (PyUnicode_Tailmatch(self->text, exec_prefix,
start, text_len, -1)) {
Py_XSETREF(self->msg,
PyUnicode_FromString("Missing parentheses in call to 'exec'"));
match = PyUnicode_Tailmatch(self->text, exec_prefix, start, text_len, -1);
if (match == -1) {
return -1;
}
if (match) {
PyObject *msg = PyUnicode_FromString("Missing parentheses in call "
"to 'exec'");
if (msg == NULL) {
return -1;
}
Py_XSETREF(self->msg, msg);
return 1;
}
/* Fall back to the default error message */
Expand Down