summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-24 19:11:26 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-24 19:11:26 -0700
commit116db7468471bc6be1c484805780b88c173f5292 (patch)
tree9d217a9e0ab069e5cc55951f09181ef2c53d5537
parente3a25eda5064b6cff8fe3f8f887f6678fa9017bc (diff)
downloadtxr-116db7468471bc6be1c484805780b88c173f5292.tar.gz
txr-116db7468471bc6be1c484805780b88c173f5292.tar.bz2
txr-116db7468471bc6be1c484805780b88c173f5292.zip
limit print depth/width when diagnosing oveflow.
* eval.c (error_trace): If the error is a stack overflow, then save the printing depth and width, and set them to stringent values, to minimize recursion in the printer. This minimizes the chances of a segfault or runaway iteration under some conditions. A repro test case is (print '#1=(#1#)) entered into the listener.
-rw-r--r--eval.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index b4ed3845..30c34836 100644
--- a/eval.c
+++ b/eval.c
@@ -390,9 +390,15 @@ void error_trace(val exsym, val exvals, val out_stream, val prefix)
val last = last_form_evaled;
val xlast = uw_last_form_expanded();
val info = source_loc_str(last, nil);
+ val max_length = nil, max_depth = nil;
uw_dump_deferred_warnings(out_stream);
+ if (uw_exception_subtype_p(exsym, stack_overflow_s)) {
+ max_length = set_max_length(out_stream, num_fast(5));
+ max_depth = set_max_depth(out_stream, num_fast(5));
+ }
+
if (cdr(exvals) || !stringp(car(exvals)))
format(out_stream, lit("~a exception args: ~!~s\n"),
prefix, exvals, nao);
@@ -481,6 +487,11 @@ void error_trace(val exsym, val exvals, val out_stream, val prefix)
#else
format(std_error, lit("~a not compiled with backtrace support\n"), prefix, nao);
#endif
+
+ if (max_length) {
+ set_max_length(out_stream, max_length);
+ set_max_depth(out_stream, max_depth);
+ }
}
val lookup_global_var(val sym)