From f222289673b4109eebe12c5dbc10f1a3dac14b95 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sun, 25 Dec 2016 00:25:49 +0100 Subject: [PATCH] Fix crash on non-computable function. When we reduced the scope of the try block in commit a823158, we introduced a bug because the tree modification was attempted even if no value was assigned (when the exception was triggered). Returning when the function is not computable ensures that this won't happen. Scaringly, there was no check that caught this. --- lslopt/lslfoldconst.py | 3 ++- testparser.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index 86bdc2a..ca3f5e8 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -974,7 +974,8 @@ class foldconst(object): value = fn(*args) except lslfuncs.ELSLCantCompute: # Don't transform the tree if function is not computable - pass + return + del args if not self.foldtabs: generatesTabs = ( diff --git a/testparser.py b/testparser.py index b856cad..8270f2b 100644 --- a/testparser.py +++ b/testparser.py @@ -504,6 +504,22 @@ class Test03_Optimizer(UnitTestCase): '}\n' ) + p = self.parser.parse('default{timer(){\n' + 'integer i = llGetAgentInfo("12345678-9ABC-DEF0-0123-456789ABCDEF");\n' + '}}\n' + ) + self.opt.optimize(p, ('optimize','constfold')) + out = self.outscript.output(p) + self.assertEqual(out, 'default\n' + '{\n' + ' timer()\n' + ' {\n' + ' integer i = llGetAgentInfo("12345678-' + '9ABC-DEF0-0123-456789ABCDEF");\n' + ' }\n' + '}\n' + ) + try: self.parser.parse('default { timer() { return } }') # should raise EParseSyntax, so it should never get here