diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2011-03-30 16:00:59 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2011-03-30 16:00:59 +0200 |
commit | a903a2ed5572b86deb323cb5471520aba05a0189 (patch) | |
tree | 6924a0051858f2ed6281d216c073bbdebaec4ff2 | |
parent | 59ff521faa134a5bd2c4de3621eeadc98d272bac (diff) | |
download | mupdf-a903a2ed5572b86deb323cb5471520aba05a0189.tar.xz |
xps: Use fz_calloc for array allocations.
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | xps/xpshash.c | 23 | ||||
-rw-r--r-- | xps/xpsjxr.c | 2 | ||||
-rw-r--r-- | xps/xpspng.c | 2 | ||||
-rw-r--r-- | xps/xpsresource.c | 2 | ||||
-rw-r--r-- | xps/xpszip.c | 10 |
6 files changed, 8 insertions, 32 deletions
@@ -176,7 +176,6 @@ MUXPS_SRC := \ xps/xpsanalyze.c \ xps/xpscolor.c \ xps/xpscommon.c \ - xps/xpscrc.c \ xps/xpsdoc.c \ xps/xpsfont.c \ xps/xpsglyphs.c \ diff --git a/xps/xpshash.c b/xps/xpshash.c index 0fdf59db..71e97097 100644 --- a/xps/xpshash.c +++ b/xps/xpshash.c @@ -53,24 +53,11 @@ xps_hash_new(xps_context *ctx) xps_hash_table *table; table = fz_malloc(sizeof(xps_hash_table)); - if (!table) - { - fz_throw("out of memory: hash table struct"); - return NULL; - } - table->size = primes[0]; table->load = 0; - table->entries = fz_malloc(sizeof(xps_hash_entry) * table->size); - if (!table->entries) - { - fz_free(table); - fz_throw("out of memory: hash table entries array"); - return NULL; - } - - memset(table->entries, 0, sizeof(xps_hash_entry) * table->size); + table->entries = fz_calloc(table->size, sizeof(xps_hash_entry)); + memset(table->entries, 0, table->size * sizeof(xps_hash_entry)); return table; } @@ -94,15 +81,13 @@ xps_hash_double(xps_context *ctx, xps_hash_table *table) } old_entries = table->entries; - new_entries = fz_malloc(sizeof(xps_hash_entry) * new_size); - if (!new_entries) - return fz_throw("out of memory: hash table entries array"); + new_entries = fz_calloc(new_size, sizeof(xps_hash_entry)); table->size = new_size; table->entries = new_entries; table->load = 0; - memset(table->entries, 0, sizeof(xps_hash_entry) * table->size); + memset(table->entries, 0, table->size * sizeof(xps_hash_entry)); for (i = 0; i < old_size; i++) if (old_entries[i].value) diff --git a/xps/xpsjxr.c b/xps/xpsjxr.c index 2ca9a22b..bbe5f66e 100644 --- a/xps/xpsjxr.c +++ b/xps/xpsjxr.c @@ -239,7 +239,7 @@ xps_decode_jpegxr(xps_context *ctx, byte *buf, int len, xps_image *output) fclose(file); unlink(name); - return gs_okay; + return fz_okay; } int diff --git a/xps/xpspng.c b/xps/xpspng.c index 526a5098..641101fe 100644 --- a/xps/xpspng.c +++ b/xps/xpspng.c @@ -249,7 +249,7 @@ xps_decode_png(xps_context *ctx, byte *rbuf, int rlen, xps_image *image) image->stride = (image->width * image->comps * image->bits + 7) / 8; - image->samples = fz_malloc(image->stride * image->height); + image->samples = fz_calloc(image->height, image->stride); for (pass = 0; pass < npasses; pass++) { diff --git a/xps/xpsresource.c b/xps/xpsresource.c index bda624e6..28c172bf 100644 --- a/xps/xpsresource.c +++ b/xps/xpsresource.c @@ -134,8 +134,6 @@ xps_parse_resource_dictionary(xps_context *ctx, xps_resource **dictp, char *base if (key) { entry = fz_malloc(sizeof(xps_resource)); - if (!entry) - return fz_throw("cannot allocate resource entry"); entry->name = key; entry->base_uri = NULL; entry->base_xml = NULL; diff --git a/xps/xpszip.c b/xps/xpszip.c index a02ce302..5528f0f7 100644 --- a/xps/xpszip.c +++ b/xps/xpszip.c @@ -22,7 +22,7 @@ static inline int getlong(FILE *file) static void * xps_zip_alloc_items(xps_context *ctx, int items, int size) { - return fz_malloc(items * size); + return fz_calloc(items, size); } static void @@ -159,10 +159,7 @@ xps_read_zip_dir(xps_context *ctx, int start_offset) offset = getlong(ctx->file); /* offset to central directory */ ctx->zip_count = count; - ctx->zip_table = fz_malloc(sizeof(xps_entry) * count); - if (!ctx->zip_table) - return fz_throw("cannot allocate zip entry table"); - + ctx->zip_table = fz_calloc(count, sizeof(xps_entry)); memset(ctx->zip_table, 0, sizeof(xps_entry) * count); fseek(ctx->file, offset, 0); @@ -191,9 +188,6 @@ xps_read_zip_dir(xps_context *ctx, int start_offset) ctx->zip_table[i].offset = getlong(ctx->file); ctx->zip_table[i].name = fz_malloc(namesize + 1); - if (!ctx->zip_table[i].name) - return fz_throw("cannot allocate zip entry name"); - fread(ctx->zip_table[i].name, 1, namesize, ctx->file); ctx->zip_table[i].name[namesize] = 0; |