emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C stack overflow in print_preprocess


From: Richard Stallman
Subject: Re: C stack overflow in print_preprocess
Date: Wed, 28 Apr 2004 06:13:15 -0400

Does this give correct results?

*** print.c     27 Apr 2004 04:36:00 -0400      1.199
--- print.c     28 Apr 2004 05:55:00 -0400      
***************
*** 1278,1283 ****
--- 1278,1301 ----
  {
    int i;
    EMACS_INT size;
+   int loop_count = 0;
+   Lisp_Object halftail;
+ 
+   /* Avoid infinite recursion for circular nested structure
+      in the case where Vprint_circle is nil.  */
+   if (NILP (Vprint_circle))
+     {
+       for (i = 0; i < print_depth; i++)
+       if (EQ (obj, being_printed[i]))
+         return;
+       being_printed[print_depth] = obj;
+     }
+ 
+   /* Give up if we go so deep that print_object will get an error.  */
+   if (print_depth >= PRINT_CIRCLE)
+     return;
+ 
+   print_depth++;
  
   loop:
    if (STRINGP (obj) || CONSP (obj) || VECTORP (obj)
***************
*** 1338,1345 ****
--- 1356,1370 ----
          break;
  
        case Lisp_Cons:
+         /* Use HALFTAIL and LOOP_COUNT to detect circular lists,
+            just as in print_object.  */
+         if (loop_count && EQ (obj, halftail))
+           break;
          print_preprocess (XCAR (obj));
          obj = XCDR (obj);
+         loop_count++;
+         if (!(loop_count & 1))
+           halftail = XCDR (halftail);
          goto loop;
  
        case Lisp_Vectorlike:
***************
*** 1354,1359 ****
--- 1379,1385 ----
          break;
        }
      }
+   print_depth--;
  }
  
  static void
***************
*** 1424,1429 ****
--- 1450,1456 ----
  
    print_depth++;
  
+   /* See similar code in print_preprocess.  */
    if (print_depth > PRINT_CIRCLE)
      error ("Apparently circular structure being printed");
  #ifdef MAX_PRINT_CHARS




reply via email to

[Prev in Thread] Current Thread [Next in Thread]