From badc0e28157fd196a254bb26d4fb4ab9f2dcea61 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Fri, 22 Nov 2013 06:14:41 +0100 Subject: [PATCH] Make sure that first-page-column does not exceed any bounds Signed-off-by: Sebastian Ramacher --- document.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/document.c b/document.c index 506fb89..722510d 100644 --- a/document.c +++ b/document.c @@ -508,11 +508,11 @@ zathura_document_get_document_size(zathura_document_t* document, { g_return_if_fail(document != NULL && height != NULL && width != NULL); - unsigned int npag = zathura_document_get_number_of_pages(document); - unsigned int ncol = zathura_document_get_pages_per_row(document); - unsigned int c0 = zathura_document_get_first_page_column(document); - unsigned int nrow = (npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */ - unsigned int pad = zathura_document_get_page_padding(document); + const unsigned int npag = zathura_document_get_number_of_pages(document); + const unsigned int ncol = zathura_document_get_pages_per_row(document); + const unsigned int c0 = zathura_document_get_first_page_column(document); + const unsigned int nrow = (npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */ + const unsigned int pad = zathura_document_get_page_padding(document); unsigned int cell_height = 0; unsigned int cell_width = 0; @@ -527,8 +527,16 @@ zathura_document_set_page_layout(zathura_document_t* document, unsigned int page unsigned int pages_per_row, unsigned int first_page_column) { g_return_if_fail(document != NULL); + document->page_padding = page_padding; document->pages_per_row = pages_per_row; + + if (first_page_column < 1) { + first_page_column = 1; + } else if (first_page_column > pages_per_row) { + first_page_column = pages_per_row; + } + document->first_page_column = first_page_column; }