summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-10-12 12:18:18 +0200
committerTor Andersson <tor.andersson@artifex.com>2016-10-12 14:45:42 +0200
commit0bb6e0b11cf2fda4ecdb89a6407d919c6ed328f5 (patch)
tree9eda479951c3dbe2ee0cd2ea9417e3a4a829044d /source
parentca8d9898719671627231c9d909cfd9ba252ab4a2 (diff)
downloadmupdf-0bb6e0b11cf2fda4ecdb89a6407d919c6ed328f5.tar.xz
Remove superfluous context null checks.
Code MUST pass a non-null context to all functions. Checking ctx for null and failing silently is no more useful than segfaulting. fz_keep_imp and fz_drop_imp handle NULL pointers safely, so the NULL checks for this can also be dropped at the same time.
Diffstat (limited to 'source')
-rw-r--r--source/fitz/document.c37
-rw-r--r--source/fitz/font.c2
-rw-r--r--source/fitz/path.c2
-rw-r--r--source/fitz/separation.c36
-rw-r--r--source/fitz/store.c11
-rw-r--r--source/gprf/gprf-doc.c6
6 files changed, 29 insertions, 65 deletions
diff --git a/source/fitz/document.c b/source/fitz/document.c
index d783bc70..fdf4d2b7 100644
--- a/source/fitz/document.c
+++ b/source/fitz/document.c
@@ -46,7 +46,7 @@ void fz_register_document_handler(fz_context *ctx, const fz_document_handler *ha
fz_document_handler_context *dc;
int i;
- if (!ctx || !handler)
+ if (!handler)
return;
dc = ctx->handler;
@@ -70,8 +70,6 @@ fz_open_document_with_stream(fz_context *ctx, const char *magic, fz_stream *stre
int best_i, best_score;
fz_document_handler_context *dc;
- if (ctx == NULL)
- return NULL;
if (magic == NULL || stream == NULL)
fz_throw(ctx, FZ_ERROR_GENERIC, "no document to open");
@@ -106,8 +104,6 @@ fz_open_document(fz_context *ctx, const char *filename)
fz_stream *file;
fz_document *doc;
- if (ctx == NULL)
- return NULL;
if (filename == NULL)
fz_throw(ctx, FZ_ERROR_GENERIC, "no document to open");
@@ -429,34 +425,29 @@ fz_page_presentation(fz_context *ctx, fz_page *page, fz_transition *transition,
int fz_count_separations_on_page(fz_context *ctx, fz_page *page)
{
- if (ctx == NULL || page == NULL || page->count_separations == NULL)
- return 0;
-
- return page->count_separations(ctx, page);
+ if (page && page->count_separations)
+ return page->count_separations(ctx, page);
+ return 0;
}
void fz_control_separation_on_page(fz_context *ctx, fz_page *page, int sep, int disable)
{
- if (ctx == NULL || page == NULL || page->control_separation == NULL)
- return;
-
- page->control_separation(ctx, page, sep, disable);
+ if (page && page->control_separation)
+ page->control_separation(ctx, page, sep, disable);
}
int fz_separation_disabled_on_page (fz_context *ctx, fz_page *page, int sep)
{
- if (ctx == NULL || page == NULL || page->separation_disabled == NULL)
- return 0;
- return page->separation_disabled(ctx, page, sep);
+ if (page && page->separation_disabled)
+ return page->separation_disabled(ctx, page, sep);
+ return 0;
}
const char *fz_get_separation_on_page(fz_context *ctx, fz_page *page, int sep, uint32_t *rgba, uint32_t *cmyk)
{
- if (ctx == NULL || page == NULL || page->get_separation == NULL)
- {
- *rgba = 0;
- *cmyk = 0;
- return NULL;
- }
- return page->get_separation(ctx, page, sep, rgba, cmyk);
+ if (page && page->get_separation)
+ return page->get_separation(ctx, page, sep, rgba, cmyk);
+ *rgba = 0;
+ *cmyk = 0;
+ return NULL;
}
diff --git a/source/fitz/font.c b/source/fitz/font.c
index 6d86133c..88d5e358 100644
--- a/source/fitz/font.c
+++ b/source/fitz/font.c
@@ -110,7 +110,7 @@ free_resources(fz_context *ctx, fz_font *font)
void fz_decouple_type3_font(fz_context *ctx, fz_font *font, void *t3doc)
{
- if (!ctx || !font || !t3doc || font->t3doc == NULL)
+ if (!font || !t3doc || font->t3doc == NULL)
return;
if (font->t3doc != t3doc)
diff --git a/source/fitz/path.c b/source/fitz/path.c
index 3befcf23..8fef2a32 100644
--- a/source/fitz/path.c
+++ b/source/fitz/path.c
@@ -1547,7 +1547,7 @@ fz_clone_path(fz_context *ctx, fz_path *path)
assert(ctx != NULL);
- if (ctx == NULL || path == NULL)
+ if (path == NULL)
return NULL;
new_path = fz_malloc_struct(ctx, fz_path);
diff --git a/source/fitz/separation.c b/source/fitz/separation.c
index 9968b574..3c6efc03 100644
--- a/source/fitz/separation.c
+++ b/source/fitz/separation.c
@@ -22,17 +22,11 @@ fz_separations *fz_new_separations(fz_context *ctx)
fz_separations *fz_keep_separations(fz_context *ctx, fz_separations *sep)
{
- if (!ctx || !sep)
- return NULL;
-
return fz_keep_imp(ctx, sep, &sep->refs);
}
void fz_drop_separations(fz_context *ctx, fz_separations *sep)
{
- if (!ctx || !sep)
- return;
-
if (fz_drop_imp(ctx, sep, &sep->refs))
{
int i;
@@ -46,12 +40,12 @@ void fz_add_separation(fz_context *ctx, fz_separations *sep, uint32_t rgb, uint3
{
int n;
- if (!ctx || !sep)
- return;
+ if (!sep)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "can't add to non-existent separations");
n = sep->num_separations;
if (n == FZ_MAX_SEPARATIONS)
- fz_throw(ctx, FZ_ERROR_GENERIC, "Too many separations");
+ fz_throw(ctx, FZ_ERROR_GENERIC, "too many separations");
sep->name[n] = fz_strdup(ctx, name);
sep->equiv_rgb[n] = rgb;
@@ -64,10 +58,8 @@ void fz_control_separation(fz_context *ctx, fz_separations *sep, int separation,
{
int bit;
- if (!ctx || !sep)
- return;
- if (separation < 0 || separation >= sep->num_separations)
- fz_throw(ctx, FZ_ERROR_GENERIC, "Can't disable non-existent separation");
+ if (!sep || separation < 0 || separation >= sep->num_separations)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "can't control non-existent separation");
bit = 1<<(separation & 31);
separation >>= 5;
@@ -97,10 +89,8 @@ int fz_separation_disabled(fz_context *ctx, fz_separations *sep, int separation)
{
int bit;
- if (!ctx || !sep)
- return 0;
- if (separation < 0 || separation >= sep->num_separations)
- fz_throw(ctx, FZ_ERROR_GENERIC, "Can't access non-existent separation");
+ if (!sep || separation < 0 || separation >= sep->num_separations)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "can't disable non-existent separation");
bit = 1<<(separation & 31);
separation >>= 5;
@@ -112,7 +102,7 @@ int fz_separations_all_enabled(fz_context *ctx, fz_separations *sep)
{
int i;
- if (!ctx || !sep)
+ if (!sep)
return 1;
for (i = 0; i < (FZ_MAX_SEPARATIONS + 31) / 32; i++)
@@ -124,11 +114,8 @@ int fz_separations_all_enabled(fz_context *ctx, fz_separations *sep)
const char *fz_get_separation(fz_context *ctx, fz_separations *sep, int separation, uint32_t *rgb, uint32_t *cmyk)
{
- if (!ctx || !sep)
- return NULL;
-
- if (separation < 0 || separation >= sep->num_separations)
- fz_throw(ctx, FZ_ERROR_GENERIC, "Can't access non-existent separation");
+ if (!sep || separation < 0 || separation >= sep->num_separations)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "can't access non-existent separation");
if (rgb)
*rgb = sep->equiv_rgb[separation];
@@ -140,8 +127,7 @@ const char *fz_get_separation(fz_context *ctx, fz_separations *sep, int separati
int fz_count_separations(fz_context *ctx, fz_separations *sep)
{
- if (!ctx || !sep)
+ if (!sep)
return 0;
-
return sep->num_separations;
}
diff --git a/source/fitz/store.c b/source/fitz/store.c
index 639e0662..2c8a7022 100644
--- a/source/fitz/store.c
+++ b/source/fitz/store.c
@@ -749,8 +749,6 @@ int fz_store_scavenge(fz_context *ctx, size_t size, int *phase)
fz_store *store;
size_t max;
- if (ctx == NULL)
- return 0;
store = ctx->store;
if (store == NULL)
return 0;
@@ -808,9 +806,6 @@ fz_shrink_store(fz_context *ctx, unsigned int percent)
fz_store *store;
size_t new_size;
- if (ctx == NULL)
- return 0;
-
if (percent >= 100)
return 1;
@@ -841,8 +836,6 @@ void fz_filter_store(fz_context *ctx, fz_store_filter_fn *fn, void *arg, fz_stor
fz_store *store;
fz_item *item, *prev, *remove;
- if (ctx == NULL)
- return;
store = ctx->store;
if (store == NULL)
return;
@@ -908,7 +901,7 @@ void fz_filter_store(fz_context *ctx, fz_store_filter_fn *fn, void *arg, fz_stor
void fz_defer_reap_start(fz_context *ctx)
{
- if (ctx == NULL || ctx->store == NULL)
+ if (ctx->store == NULL)
return;
fz_lock(ctx, FZ_LOCK_REAP);
@@ -920,7 +913,7 @@ void fz_defer_reap_end(fz_context *ctx)
{
int reap;
- if (ctx == NULL || ctx->store == NULL)
+ if (ctx->store == NULL)
return;
fz_lock(ctx, FZ_LOCK_ALLOC);
diff --git a/source/gprf/gprf-doc.c b/source/gprf/gprf-doc.c
index 8d6b3b32..9f9d5ebb 100644
--- a/source/gprf/gprf-doc.c
+++ b/source/gprf/gprf-doc.c
@@ -88,18 +88,12 @@ fz_new_gprf_file(fz_context *ctx, char *filename)
static gprf_file *
fz_keep_gprf_file(fz_context *ctx, gprf_file *file)
{
- if (!ctx || !file)
- return NULL;
-
return fz_keep_imp(ctx, file, &file->refs);
}
static void
fz_drop_gprf_file(fz_context *ctx, gprf_file *file)
{
- if (!ctx || !file)
- return;
-
if (fz_drop_imp(ctx, file, &file->refs))
{
unlink(file->filename);