From 853f34b488654e35019286c0ba2f1942935958a4 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Sat, 15 Sep 2012 22:19:12 +0100 Subject: [PATCH] Fix for calculating the current position in the case of TOC containing links to external files: when walking the TOC we should check if the destination page is within the range of the current document. --- unireader.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unireader.lua b/unireader.lua index 31b15959e..5b255e196 100644 --- a/unireader.lua +++ b/unireader.lua @@ -1740,10 +1740,11 @@ end -- corresponding to the current page. function UniReader:findTOCpos() local pos, found_pos = 0, false + local numpages = self.doc:getPages() -- find the index into toc_xview first for k,v in ipairs(self.toc) do - if v.page > self.pageno then + if v.page >= 1 and v.page <= self.doc:getPages() and v.page > self.pageno then pos = k - 1 found_pos = true break