pitermarx / NCalc2

Clone of NCalc, ported to netstandard2.0
MIT License
11 stars 3 forks source link

Circular reference causes stack overflow #6

Open mosseb opened 6 years ago

mosseb commented 6 years ago

As discussed in https://github.com/pitermarx/NCalc-Edge/issues/14, when using circular references, the Evaluate method leads to a StackOverflowException (which is not catchable). For user written expressions, this is a blocking problem. For example :

NCalc.Expression exp = new NCalc.Expression("RefCroise1"); exp.Parameters["RefCroise1"] = new NCalc.Expression("RefCroise2 5"); exp.Parameters["RefCroise2"] = new NCalc.Expression("RefCroise1 12"); object result = exp.Evaluate(); // Causes stack overflow

.hasErrors() neither detects it.

I think this is a major error to be detected, as this is crashing the program.

Nota : I did not check how it is in NCalc2 but as @pitermarx asked, I'm creating the PR here. Thanks.

pitermarx commented 6 years ago

I asked for a Pull Request not just an issue. But let's leave it here. Maybe sometime i can get to it