summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-12-18 19:22:00 +0000
committerRobin Watts <robin.watts@artifex.com>2012-12-18 20:30:37 +0000
commit1f39afecc00df83ff3306f81716483d843e3f70e (patch)
tree79ea5f2fca23871f2692431cd59acd4db4d55f51
parentd54880994238be020d5e7298b45eb74ae5e846b6 (diff)
downloadmupdf-1f39afecc00df83ff3306f81716483d843e3f70e.tar.xz
Memento: Avoid stack overflows while listing leaked blocks.
Leaking long linked lists leads to stack overflows during the Memento debug output. Avoid this by iterating rather than recursing where possible. Also, for sanities sake, where we intent more than 40 spaces, use a single '*' instead. This keeps logfiles sane.
-rw-r--r--fitz/memento.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/fitz/memento.c b/fitz/memento.c
index dcd417b8..7c3c6200 100644
--- a/fitz/memento.c
+++ b/fitz/memento.c
@@ -474,6 +474,11 @@ static void showBlock(Memento_BlkHeader *b, int space)
static void blockDisplay(Memento_BlkHeader *b, int n)
{
n++;
+ while (n > 40)
+ {
+ fprintf(stderr, "*");
+ n -= 40;
+ }
while(n > 0)
{
int i = n;
@@ -499,9 +504,18 @@ static int Memento_listBlock(Memento_BlkHeader *b,
static void doNestedDisplay(Memento_BlkHeader *b,
int depth)
{
- blockDisplay(b, depth);
- for (b = b->child; b; b = b->sibling)
- doNestedDisplay(b, depth+1);
+ /* Try and avoid recursion if we can help it */
+ do {
+ blockDisplay(b, depth);
+ if (b->sibling) {
+ if (b->child)
+ doNestedDisplay(b->child, depth+1);
+ b = b->sibling;
+ } else {
+ b = b->child;
+ depth++;
+ }
+ } while (b);
}
static int ptrcmp(const void *a_, const void *b_)