diff options
author | Andrey Kiselev <dron@ak4719.spb.edu> | 2004-10-03 08:34:01 +0000 |
---|---|---|
committer | Andrey Kiselev <dron@ak4719.spb.edu> | 2004-10-03 08:34:01 +0000 |
commit | 26eb4ec2ed7a7640630a0a1e5aeb549f1916c899 (patch) | |
tree | a578ae0e059f6a53187f288820679f946fa22f8f | |
parent | 9f33c698e0122e80e73e94950c09c519eeec97f7 (diff) | |
download | libtiff-git-26eb4ec2ed7a7640630a0a1e5aeb549f1916c899.tar.gz |
Improved error reporting in TIFFGetConfiguredCODECs() (Dmitry V. Levin).
-rw-r--r-- | libtiff/tif_compress.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/libtiff/tif_compress.c b/libtiff/tif_compress.c index bc18a5b6..718f0921 100644 --- a/libtiff/tif_compress.c +++ b/libtiff/tif_compress.c @@ -1,4 +1,4 @@ -/* $Id: tif_compress.c,v 1.8 2004-10-02 13:29:41 dron Exp $ */ +/* $Id: tif_compress.c,v 1.9 2004-10-03 08:34:01 dron Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -233,9 +233,10 @@ TIFFUnRegisterCODEC(TIFFCodec* c) /** * Get list of configured codecs, both built-in and registered by user. - * Caller is responsible to free these structure. + * Caller is responsible to free this structure. * - * @return returns array of TIFFCodec records, the last record should be NULL. + * @return returns array of TIFFCodec records (the last record should be NULL) + * or NULL if function failed. */ TIFFCodec* @@ -244,25 +245,37 @@ TIFFGetConfiguredCODECs() int i = 1; codec_t *cd; const TIFFCodec *c; - TIFFCodec *codecs = NULL; + TIFFCodec *codecs = NULL, *new_codecs; for (cd = registeredCODECS; cd; cd = cd->next) { - codecs = _TIFFrealloc(codecs, i * sizeof(TIFFCodec)); - assert (codecs == NULL); + new_codecs = _TIFFrealloc(codecs, i * sizeof(TIFFCodec)); + if (!new_codecs) { + _TIFFfree (codecs); + return NULL; + } + codecs = new_codecs; _TIFFmemcpy(codecs + i - 1, cd, sizeof(TIFFCodec)); i++; } for (c = _TIFFBuiltinCODECS; c->name; c++) { if (TIFFIsCODECConfigured(c->scheme)) { - codecs = _TIFFrealloc(codecs, i * sizeof(TIFFCodec)); - assert (codecs == NULL); + new_codecs = _TIFFrealloc(codecs, i * sizeof(TIFFCodec)); + if (!new_codecs) { + _TIFFfree (codecs); + return NULL; + } + codecs = new_codecs; _TIFFmemcpy(codecs + i - 1, (const tdata_t)c, sizeof(TIFFCodec)); i++; } } - codecs = _TIFFrealloc(codecs, i * sizeof(TIFFCodec)); - assert (codecs == NULL); + new_codecs = _TIFFrealloc(codecs, i * sizeof(TIFFCodec)); + if (!new_codecs) { + _TIFFfree (codecs); + return NULL; + } + codecs = new_codecs; _TIFFmemset(codecs + i - 1, 0, sizeof(TIFFCodec)); return codecs; |