]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Tim Peters fixed PR#75: very long lines cause incorrect tracebacks.
authorGuido van Rossum <guido@python.org>
Sat, 18 Sep 1999 20:49:39 +0000 (20:49 +0000)
committerGuido van Rossum <guido@python.org>
Sat, 18 Sep 1999 20:49:39 +0000 (20:49 +0000)
Python/traceback.c

index 53b84f307ea3e45e9220f582a414d618cc96255a..ca77eaa62a69cad4edfffb64243b1e30aad38aae 100644 (file)
@@ -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;