|
|
- From 2d38a12d686a5156d4e7afb1fed7851805590582 Mon Sep 17 00:00:00 2001
- From: W-Mark Kubacki <wmark@hurrikane.de>
- Date: Fri, 19 Aug 2016 19:50:39 +0200
- Subject: [PATCH] Skip printing at MAX_DEPTH and deeper
-
- This addresses #1136, and mitigates a stack exhaustion when printing
- a very deeply nested term.
- ---
- src/jv_print.c | 8 +++++++-
- 1 file changed, 7 insertions(+), 1 deletion(-)
-
- diff --git a/src/jv_print.c b/src/jv_print.c
- index 5f4f234..cf6651b 100644
- --- src/jv_print.c
- +++ src/jv_print.c
- @@ -13,6 +13,10 @@
- #include "jv_dtoa.h"
- #include "jv_unicode.h"
-
- +#ifndef MAX_DEPTH
- +#define MAX_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_DEPTH) {
- + put_str("<stripped: exceeds max depth>", F, S, flags & JV_PRINT_ISATTY);
- + } else switch (jv_get_kind(x)) {
- default:
- case JV_KIND_INVALID:
- if (flags & JV_PRINT_INVALID) {
|