Assign document object iff pages exist

Only saves the document object iff the opened document contains pages. In
addition a check is implemented such that the nrow calculation does not crash.
This commit is contained in:
Moritz Lipp 2016-03-09 16:21:12 +01:00
parent 7e84b67259
commit 3bc1d819a4
2 changed files with 9 additions and 4 deletions

View file

@ -520,6 +520,11 @@ zathura_document_get_document_size(zathura_document_t* document,
const unsigned int npag = zathura_document_get_number_of_pages(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 ncol = zathura_document_get_pages_per_row(document);
if (npag == 0 || ncol == 0) {
return;
}
const unsigned int c0 = zathura_document_get_first_page_column(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 nrow = (npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */
const unsigned int pad = zathura_document_get_page_padding(document); const unsigned int pad = zathura_document_get_page_padding(document);

View file

@ -791,8 +791,6 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char*
goto error_out; goto error_out;
} }
zathura->document = document;
const char* file_path = zathura_document_get_path(document); const char* file_path = zathura_document_get_path(document);
unsigned int number_of_pages = zathura_document_get_number_of_pages(document); unsigned int number_of_pages = zathura_document_get_number_of_pages(document);
@ -802,6 +800,8 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char*
goto error_free; goto error_free;
} }
zathura->document = document;
/* read history file */ /* read history file */
zathura_fileinfo_t file_info = { zathura_fileinfo_t file_info = {
.current_page = 0, .current_page = 0,