From 904ee3bf26f863b7b31c4085f511e54c0307e537 Mon Sep 17 00:00:00 2001 From: W-Mark Kubacki Date: Fri, 19 Aug 2016 19:50:39 +0200 Subject: [PATCH] Skip printing what's below a MAX_PRINT_DEPTH This addresses #1136, and mitigates a stack exhaustion when printing a very deeply nested term. --- jv_print.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/jv_print.c b/src/jv_print.c index 5f4f234b..ce4a59af 100644 --- a/jv_print.c +++ b/jv_print.c @@ -13,6 +13,10 @@ #include "jv_dtoa.h" #include "jv_unicode.h" +#ifndef MAX_PRINT_DEPTH +#define MAX_PRINT_DEPTH (256) +#endif + #define ESC "\033" #define COL(c) (ESC "[" c "m") #define COLRESET (ESC "[0m") @@ -150,7 +154,9 @@ static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FI } } } - switch (jv_get_kind(x)) { + if (indent > MAX_PRINT_DEPTH) { + put_str("", F, S, flags & JV_PRINT_ISATTY); + } else switch (jv_get_kind(x)) { default: case JV_KIND_INVALID: if (flags & JV_PRINT_INVALID) {