Skip to content

Commit e5001fb

Browse files
author
guido
committed
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
git-svn-id: http://svn.python.org/projects/python/trunk@13833 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent b7a6c6e commit e5001fb

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

Python/traceback.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,17 @@ tb_displayline(f, filename, lineno, name)
197197
if (xfp == NULL || err != 0)
198198
return err;
199199
for (i = 0; i < lineno; i++) {
200-
if (fgets(linebuf, sizeof linebuf, xfp) == NULL)
201-
break;
200+
char* pLastChar = &linebuf[sizeof(linebuf)-2];
201+
do {
202+
*pLastChar = '\0';
203+
if (fgets(linebuf, sizeof linebuf, xfp) == NULL)
204+
break;
205+
/* fgets read *something*; if it didn't get as
206+
far as pLastChar, it must have found a newline
207+
or hit the end of the file; if pLastChar is \n,
208+
it obviously found a newline; else we haven't
209+
yet seen a newline, so must continue */
210+
} while (*pLastChar != '\0' && *pLastChar != '\n');
202211
}
203212
if (i == lineno) {
204213
char *p = linebuf;

0 commit comments

Comments
 (0)