From 4835199125415dbd40d863ea945a71bab9b6962b Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 5 Apr 2014 21:05:07 +0200 Subject: [PATCH] new VM: proper shield against endless recursions --- compiler/vm.nim | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/vm.nim b/compiler/vm.nim index b365dba9a..fb8749250 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -48,9 +48,17 @@ type # XXX 'break' should perform cleanup actions # What does the C backend do for it? -proc stackTraceAux(c: PCtx; x: PStackFrame; pc: int) = +proc stackTraceAux(c: PCtx; x: PStackFrame; pc: int; recursionLimit=100) = if x != nil: - stackTraceAux(c, x.next, x.comesFrom) + if recursionLimit == 0: + var calls = 0 + var x = x + while x != nil: + inc calls + x = x.next + msgWriteln($calls & " calls omitted\n") + return + stackTraceAux(c, x.next, x.comesFrom, recursionLimit-1) var info = c.debug[pc] # we now use the same format as in system/except.nim var s = toFilename(info)