mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
This commit is contained in:
parent
458e7fab9b
commit
3aca65312a
1 changed files with 11 additions and 2 deletions
|
|
@ -197,8 +197,17 @@ tb_displayline(f, filename, lineno, name)
|
||||||
if (xfp == NULL || err != 0)
|
if (xfp == NULL || err != 0)
|
||||||
return err;
|
return err;
|
||||||
for (i = 0; i < lineno; i++) {
|
for (i = 0; i < lineno; i++) {
|
||||||
if (fgets(linebuf, sizeof linebuf, xfp) == NULL)
|
char* pLastChar = &linebuf[sizeof(linebuf)-2];
|
||||||
break;
|
do {
|
||||||
|
*pLastChar = '\0';
|
||||||
|
if (fgets(linebuf, sizeof linebuf, xfp) == NULL)
|
||||||
|
break;
|
||||||
|
/* fgets read *something*; if it didn't get as
|
||||||
|
far as pLastChar, it must have found a newline
|
||||||
|
or hit the end of the file; if pLastChar is \n,
|
||||||
|
it obviously found a newline; else we haven't
|
||||||
|
yet seen a newline, so must continue */
|
||||||
|
} while (*pLastChar != '\0' && *pLastChar != '\n');
|
||||||
}
|
}
|
||||||
if (i == lineno) {
|
if (i == lineno) {
|
||||||
char *p = linebuf;
|
char *p = linebuf;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue