diff options
| author | Richard M. Stallman | 2004-05-10 16:55:38 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2004-05-10 16:55:38 +0000 |
| commit | c11326718786ba5aa701fd9ba97c57876deab90e (patch) | |
| tree | 39c5873c5097da0d2dc300a9f002e6dbf64abf6e /src | |
| parent | 6740652e6d63701107312f7dd1efcc623c4b38fc (diff) | |
| download | emacs-c11326718786ba5aa701fd9ba97c57876deab90e.tar.gz emacs-c11326718786ba5aa701fd9ba97c57876deab90e.zip | |
(print_preprocess): Use being_printed, loop_count and
halftail to detect overdeep nesting and cyclic cdr chains.
Diffstat (limited to 'src')
| -rw-r--r-- | src/print.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/print.c b/src/print.c index e729b468fd1..27da81ae8eb 100644 --- a/src/print.c +++ b/src/print.c | |||
| @@ -1280,6 +1280,26 @@ print_preprocess (obj) | |||
| 1280 | { | 1280 | { |
| 1281 | int i; | 1281 | int i; |
| 1282 | EMACS_INT size; | 1282 | EMACS_INT size; |
| 1283 | int loop_count = 0; | ||
| 1284 | Lisp_Object halftail; | ||
| 1285 | |||
| 1286 | /* Avoid infinite recursion for circular nested structure | ||
| 1287 | in the case where Vprint_circle is nil. */ | ||
| 1288 | if (NILP (Vprint_circle)) | ||
| 1289 | { | ||
| 1290 | for (i = 0; i < print_depth; i++) | ||
| 1291 | if (EQ (obj, being_printed[i])) | ||
| 1292 | return; | ||
| 1293 | being_printed[print_depth] = obj; | ||
| 1294 | } | ||
| 1295 | |||
| 1296 | /* Give up if we go so deep that print_object will get an error. */ | ||
| 1297 | /* See similar code in print_object. */ | ||
| 1298 | if (print_depth >= PRINT_CIRCLE) | ||
| 1299 | return; | ||
| 1300 | |||
| 1301 | print_depth++; | ||
| 1302 | halftail = obj; | ||
| 1283 | 1303 | ||
| 1284 | loop: | 1304 | loop: |
| 1285 | if (STRINGP (obj) || CONSP (obj) || VECTORP (obj) | 1305 | if (STRINGP (obj) || CONSP (obj) || VECTORP (obj) |
| @@ -1340,8 +1360,15 @@ print_preprocess (obj) | |||
| 1340 | break; | 1360 | break; |
| 1341 | 1361 | ||
| 1342 | case Lisp_Cons: | 1362 | case Lisp_Cons: |
| 1363 | /* Use HALFTAIL and LOOP_COUNT to detect circular lists, | ||
| 1364 | just as in print_object. */ | ||
| 1365 | if (loop_count && EQ (obj, halftail)) | ||
| 1366 | break; | ||
| 1343 | print_preprocess (XCAR (obj)); | 1367 | print_preprocess (XCAR (obj)); |
| 1344 | obj = XCDR (obj); | 1368 | obj = XCDR (obj); |
| 1369 | loop_count++; | ||
| 1370 | if (!(loop_count & 1)) | ||
| 1371 | halftail = XCDR (halftail); | ||
| 1345 | goto loop; | 1372 | goto loop; |
| 1346 | 1373 | ||
| 1347 | case Lisp_Vectorlike: | 1374 | case Lisp_Vectorlike: |
| @@ -1356,6 +1383,7 @@ print_preprocess (obj) | |||
| 1356 | break; | 1383 | break; |
| 1357 | } | 1384 | } |
| 1358 | } | 1385 | } |
| 1386 | print_depth--; | ||
| 1359 | } | 1387 | } |
| 1360 | 1388 | ||
| 1361 | static void | 1389 | static void |
| @@ -1426,6 +1454,7 @@ print_object (obj, printcharfun, escapeflag) | |||
| 1426 | 1454 | ||
| 1427 | print_depth++; | 1455 | print_depth++; |
| 1428 | 1456 | ||
| 1457 | /* See similar code in print_preprocess. */ | ||
| 1429 | if (print_depth > PRINT_CIRCLE) | 1458 | if (print_depth > PRINT_CIRCLE) |
| 1430 | error ("Apparently circular structure being printed"); | 1459 | error ("Apparently circular structure being printed"); |
| 1431 | #ifdef MAX_PRINT_CHARS | 1460 | #ifdef MAX_PRINT_CHARS |