From: Guido van Rossum Date: Sat, 18 Sep 1999 20:49:39 +0000 (+0000) Subject: Tim Peters fixed PR#75: very long lines cause incorrect tracebacks. X-Git-Tag: v1.6a1~912 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3aca65312a9b6c5fe741167764d56de073259f73;p=thirdparty%2FPython%2Fcpython.git Tim Peters fixed PR#75: very long lines cause incorrect tracebacks. --- diff --git a/Python/traceback.c b/Python/traceback.c index 53b84f307ea3..ca77eaa62a69 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -197,8 +197,17 @@ tb_displayline(f, filename, lineno, name) if (xfp == NULL || err != 0) return err; for (i = 0; i < lineno; i++) { - if (fgets(linebuf, sizeof linebuf, xfp) == NULL) - break; + char* pLastChar = &linebuf[sizeof(linebuf)-2]; + 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) { char *p = linebuf;