diff options
author | Guido van Rossum <guido@python.org> | 1999-09-18 20:49:39 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-09-18 20:49:39 +0000 |
commit | ab484ae12d2a23089362c8bc762595f5cab79dff (patch) | |
tree | 30ab18ae30f71e2e312a865c9a9d3c1214906c60 /Python/traceback.c | |
parent | 2749a8ac02c74d379da2eb09ed9b181b98c95665 (diff) | |
download | cpython-ab484ae12d2a23089362c8bc762595f5cab79dff.tar.gz |
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
Diffstat (limited to 'Python/traceback.c')
-rw-r--r-- | Python/traceback.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Python/traceback.c b/Python/traceback.c index 53b84f307e..ca77eaa62a 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; |