From 4c88e9d1ef196e286a82a3b68d1334b3966ed871 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Fri, 22 Nov 2013 06:23:22 +0100 Subject: [PATCH] Make sure we do not underflow --- adjustment.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/adjustment.c b/adjustment.c index b162419..af07009 100644 --- a/adjustment.c +++ b/adjustment.c @@ -69,7 +69,12 @@ position_to_page_number(zathura_document_t* document, double pos_x, unsigned int col = floor(pos_x * (double)doc_width / (double)(cell_width + pad)); unsigned int row = floor(pos_y * (double)doc_height / (double)(cell_height + pad)); - return ncol * (row % nrow) + (col % ncol) - (c0 - 1); + unsigned int page = ncol * (row % nrow) + (col % ncol); + if (page < c0 - 1) { + return 0; + } else { + return page - (c0 - 1); + } }