diff options
author | Robin Watts <Robin.Watts@artifex.com> | 2011-10-04 18:44:19 +0100 |
---|---|---|
committer | Robin Watts <Robin.Watts@artifex.com> | 2011-10-04 18:44:19 +0100 |
commit | d208be26537db558edb70236ae517cea31b7ebab (patch) | |
tree | 57da95b97e354a53bd4517a42010e90968f007d9 /fitz/base_memory.c | |
parent | ba46cad4b09bb957085900a203206c8fa5868cd4 (diff) | |
download | mupdf-d208be26537db558edb70236ae517cea31b7ebab.tar.xz |
Move to exception handling rather than error passing throughout.
This frees us from passing errors back everywhere, and hence enables us
to pass results back as return values.
Rather than having to explicitly check for errors everywhere and bubble
them, we now allow exception handling to do the work for us; the
downside to this is that we no longer emit as much debugging information
as we did before (though this could be put back in). For now, the
debugging information we have lost has been retained in comments
with 'RJW:' at the start.
This code needs fuller testing, but is being committed as a work in
progress.
Diffstat (limited to 'fitz/base_memory.c')
-rw-r--r-- | fitz/base_memory.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/fitz/base_memory.c b/fitz/base_memory.c index 27474cc3..cf972542 100644 --- a/fitz/base_memory.c +++ b/fitz/base_memory.c @@ -36,6 +36,29 @@ fz_malloc_array(fz_context *ctx, unsigned int count, unsigned int size) } void * +fz_calloc(fz_context *ctx, unsigned int count, unsigned int size) +{ + void *p; + + if (count == 0 || size == 0) + return 0; + + if (count > UINT_MAX / size) + { + fprintf(stderr, "fatal error: out of memory (integer overflow)\n"); + abort(); + } + + p = calloc(count, size); + if (!p) + { + fprintf(stderr, "fatal error: out of memory\n"); + abort(); + } + return p; +} + +void * fz_resize_array(fz_context *ctx, void *p, unsigned int count, unsigned int size) { void *np; |