From 6cc97e85489f5e4e39aa185d17ad5e35b09dddb5 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 13 Feb 2015 12:16:06 +0100 Subject: Remove pointless return value checks when calling fz_open_file. fz_open_file does not return NULL on failure -- it throws an exception! --- source/cbz/mucbz.c | 2 -- source/cbz/muimg.c | 2 -- source/cbz/mutiff.c | 22 ++-------------------- source/fitz/unzip.c | 7 +------ source/xps/xps-zip.c | 9 +-------- 5 files changed, 4 insertions(+), 38 deletions(-) (limited to 'source') diff --git a/source/cbz/mucbz.c b/source/cbz/mucbz.c index 75148490..8ea782aa 100644 --- a/source/cbz/mucbz.c +++ b/source/cbz/mucbz.c @@ -230,8 +230,6 @@ cbz_open_document(fz_context *ctx, const char *filename) cbz_document *doc; file = fz_open_file(ctx, filename); - if (!file) - fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); fz_try(ctx) doc = cbz_open_document_with_stream(ctx, file); diff --git a/source/cbz/muimg.c b/source/cbz/muimg.c index a288a4f4..0680c15a 100644 --- a/source/cbz/muimg.c +++ b/source/cbz/muimg.c @@ -145,8 +145,6 @@ img_open_document(fz_context *ctx, const char *filename) img_document *doc; stm = fz_open_file(ctx, filename); - if (!stm) - fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); fz_try(ctx) doc = img_open_document_with_stream(ctx, stm); diff --git a/source/cbz/mutiff.c b/source/cbz/mutiff.c index c03cb3b7..c0b9cff0 100644 --- a/source/cbz/mutiff.c +++ b/source/cbz/mutiff.c @@ -14,7 +14,6 @@ struct tiff_page_s struct tiff_document_s { fz_document super; - fz_stream *file; fz_buffer *buffer; int page_count; }; @@ -118,7 +117,6 @@ static void tiff_close_document(fz_context *ctx, tiff_document *doc) { fz_drop_buffer(ctx, doc->buffer); - fz_drop_stream(ctx, doc->file); fz_free(ctx, doc); } @@ -126,8 +124,6 @@ static tiff_document * tiff_open_document_with_stream(fz_context *ctx, fz_stream *file) { tiff_document *doc; - unsigned char *buf; - int len; doc = fz_new_document(ctx, sizeof *doc); @@ -136,16 +132,10 @@ tiff_open_document_with_stream(fz_context *ctx, fz_stream *file) doc->super.load_page = (fz_document_load_page_fn *)tiff_load_page; doc->super.meta = (fz_document_meta_fn *)tiff_meta; - doc->file = fz_keep_stream(ctx, file); - doc->page_count = 0; - fz_try(ctx) { - doc->buffer = fz_read_all(ctx, doc->file, 1024); - len = doc->buffer->len; - buf = doc->buffer->data; - - doc->page_count = fz_load_tiff_subimage_count(ctx, buf, len); + doc->buffer = fz_read_all(ctx, file, 1024); + doc->page_count = fz_load_tiff_subimage_count(ctx, doc->buffer->data, doc->buffer->len); } fz_catch(ctx) { @@ -163,21 +153,13 @@ tiff_open_document(fz_context *ctx, const char *filename) tiff_document *doc; file = fz_open_file(ctx, filename); - if (!file) - fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); fz_try(ctx) - { doc = tiff_open_document_with_stream(ctx, file); - } fz_always(ctx) - { fz_drop_stream(ctx, file); - } fz_catch(ctx) - { fz_rethrow(ctx); - } return doc; } diff --git a/source/fitz/unzip.c b/source/fitz/unzip.c index 8c8a6ba3..23028d42 100644 --- a/source/fitz/unzip.c +++ b/source/fitz/unzip.c @@ -504,18 +504,13 @@ fz_open_archive(fz_context *ctx, const char *filename) fz_archive *zip; file = fz_open_file(ctx, filename); + fz_try(ctx) - { zip = fz_open_archive_with_stream(ctx, file); - } fz_always(ctx) - { fz_drop_stream(ctx, file); - } fz_catch(ctx) - { fz_rethrow(ctx); - } return zip; } diff --git a/source/xps/xps-zip.c b/source/xps/xps-zip.c index ab8c60d7..3759c4b6 100644 --- a/source/xps/xps-zip.c +++ b/source/xps/xps-zip.c @@ -182,21 +182,14 @@ xps_open_document(fz_context *ctx, const char *filename) } file = fz_open_file(ctx, filename); - if (!file) - fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); fz_try(ctx) - { doc = xps_open_document_with_stream(ctx, file); - } fz_always(ctx) - { fz_drop_stream(ctx, file); - } fz_catch(ctx) - { fz_rethrow_message(ctx, "cannot load document '%s'", filename); - } + return doc; } -- cgit v1.2.3