Mercurial > cpython-lru_cache-weakref
diff Python/traceback.c @ 11294:d3696bf08eee legacy-trunk
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sat, 18 Sep 1999 20:49:39 +0000 |
| parents | 79e49cbce2ef |
| children | c94247b5c355 |
line wrap: on
line diff
--- a/Python/traceback.c Fri Sep 17 15:40:40 1999 +0000 +++ b/Python/traceback.c Sat Sep 18 20:49:39 1999 +0000 @@ -197,8 +197,17 @@ 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;
