Skip to content

bpo-40612: Fix SyntaxError edge cases in traceback formatting #20072

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
merged 8 commits into from
May 15, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Apply PEP 7 suggestions from code review
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
  • Loading branch information
gvanrossum and pablogsal authored May 15, 2020
commit 31641ff0e4b18c8d002d019f4506f0e8fb446983
18 changes: 12 additions & 6 deletions Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,21 +570,25 @@ print_error_text(PyObject *f, int offset, PyObject *text_obj)

/* Calculate text length excluding trailing newline */
Py_ssize_t len = strlen(text);
if (len > 0 && text[len-1] == '\n')
if (len > 0 && text[len-1] == '\n') {
len--;
}

/* Clip offset to at most len */
if (offset > len)
if (offset > len) {
offset = len;
}

/* Skip past newlines embedded in text */
for (;;) {
const char *nl = strchr(text, '\n');
if (nl == NULL)
if (nl == NULL) {
break;
}
Py_ssize_t inl = nl - text;
if (inl >= (Py_ssize_t)offset)
if (inl >= (Py_ssize_t)offset) {
break;
}
inl += 1;
text += inl;
len -= inl;
Expand All @@ -596,17 +600,19 @@ print_error_text(PyObject *f, int offset, PyObject *text_obj)
PyFile_WriteString(text, f);

/* Make sure there's a newline at the end */
if (text[len] != '\n')
if (text[len] != '\n') {
PyFile_WriteString("\n", f);
}

/* Don't print caret if it points to the left of the text */
if (offset < 0)
return;

/* Write caret line */
PyFile_WriteString(" ", f);
while (--offset >= 0)
while (--offset >= 0) {
PyFile_WriteString(" ", f);
}
PyFile_WriteString("^\n", f);
}

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy