Skip to content

Commit

Permalink
Skip printing what's below a MAX_PRINT_DEPTH
Browse files Browse the repository at this point in the history
This addresses #1136, and mitigates a stack exhaustion when printing
a very deeply nested term.
  • Loading branch information
mark-kubacki authored and nicowilliams committed Jan 27, 2017
1 parent 61b7563 commit 83e2cf6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/jv_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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("<skipped: too deep>", F, S, flags & JV_PRINT_ISATTY);
} else switch (jv_get_kind(x)) {
default:
case JV_KIND_INVALID:
if (flags & JV_PRINT_INVALID) {
Expand Down

0 comments on commit 83e2cf6

Please sign in to comment.