From 79c1dd44ca4c4940e0ddeafb2d98e409ca3c729a Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Sun, 30 Sep 2012 16:06:55 +0100 Subject: [PATCH 1/2] Restrict the values of rcountmax to the range 0-10 Currently the user can enter any value like -10 and it is accepted and saved in the settings file(s). --- unireader.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unireader.lua b/unireader.lua index 20e740b26..c942b70d3 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2490,7 +2490,7 @@ function UniReader:addAllCommands() if pcall(function () count = count + 0 end) then -- restrict self.rcountmax in reasonable range self.rcountmax = math.max(count, 0) - self.rcountmax = math.min(count, 10) + self.rcountmax = math.min(self.rcountmax, 10) -- storing this parameter in both global and local settings G_reader_settings:saveSetting("rcountmax", self.rcountmax) self.settings:saveSetting("rcountmax", self.rcountmax) From 72f669ff3c2f95da60ba87a48694517cfdff7e41 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Sun, 30 Sep 2012 18:28:10 +0100 Subject: [PATCH 2/2] Don't allow floating point values for rcountmax This is a better version of the previous commit, which: a) makes the code more readable b) disallows rcountmax values like "6.05", i.e. restricts to integers only. --- unireader.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/unireader.lua b/unireader.lua index c942b70d3..607c271b4 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2487,10 +2487,13 @@ function UniReader:addAllCommands() local count = NumInputBox:input(G_height-100, 100, "Full refresh after:", self.rcountmax, true) -- convert string to number - if pcall(function () count = count + 0 end) then - -- restrict self.rcountmax in reasonable range - self.rcountmax = math.max(count, 0) - self.rcountmax = math.min(self.rcountmax, 10) + if pcall(function () count = math.floor(count) end) then + if count < 0 then + count = 0 + elseif count > 10 then + count = 10 + end + self.rcountmax = count -- storing this parameter in both global and local settings G_reader_settings:saveSetting("rcountmax", self.rcountmax) self.settings:saveSetting("rcountmax", self.rcountmax)