From 4f2be7a7e82127424bfd42a7436c61c8e27e219d Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Fri, 14 Sep 2012 18:36:55 +0100 Subject: [PATCH] Calculator: make it more robust. Previously it was very easy to crash the application by entering invalid input into calculator, for example things like these: ")(", "inf/0", "f()", etc. By using Lua pcall() function to execute not only the construction of the expression, but also the calculation of the final result, the calculator is made more robust and safe-guarded from such crashes. --- inputbox.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inputbox.lua b/inputbox.lua index ae0150e1e..84198cce0 100644 --- a/inputbox.lua +++ b/inputbox.lua @@ -604,8 +604,7 @@ function InputBox:ModeDependentCommands() showInfoMsgWithDelay("No input ", 1000, 1) else local s = self:PrepareStringToCalc() - if pcall(function () f = assert(loadstring("r = tostring("..s..")")) end) then - f() + if pcall(function () f = assert(loadstring("r = tostring("..s..")")) end) and pcall(f) then self:clearText() self.cursor:clear() for i=1, string.len(r) do