提交 f18a0ed3 编写于 作者: G Glenn Randers-Pehrson

[devel] Simplified the pngvalid error-handling code

 now that cexcept.h is in place.
上级 92ac4fc2
......@@ -372,6 +372,7 @@ Version 1.5.0beta44 [August 11, 2010]
Reformatted/rearranged pngvalid.c to assist use of progressive reader.
Check interlaced images in pngvalid
Clarified pngusr.h comments in pnglibconf.dfa
Simplified the pngvalid error-handling code now that cexcept.h is in place.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net:
(subscription required; visit
......
......@@ -3009,6 +3009,7 @@ Version 1.5.0beta44 [August 11, 2010]
Reformatted/rearranged pngvalid.c to assist use of progressive reader.
Check interlaced images in pngvalid
Clarified pngusr.h comments in pnglibconf.dfa
Simplified the pngvalid error-handling code now that cexcept.h is in place.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit
......
......@@ -952,42 +952,45 @@ static png_structp
set_store_for_read(png_store *ps, png_infopp ppi, png_uint_32 id,
PNG_CONST char *name)
{
context(ps, fault);
png_structp result = NULL;
/* NOTE: reference to 'name' must be outside the Try block or GCC can
* optimize it away.
*/
/* Set the name for png_error */
safecat(ps->test, sizeof ps->test, 0, name);
Try
{
if (ps->pread != NULL)
png_error(ps->pread, "store already in use");
if (ps->pread != NULL)
png_error(ps->pread, "store already in use");
store_read_reset(ps);
store_read_reset(ps);
if (ps->speed)
ps->pread = png_create_read_struct(PNG_LIBPNG_VER_STRING, ps,
store_error, store_warning);
else
ps->pread = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, ps,
store_error, store_warning, &ps->read_memory_pool, store_malloc,
store_free);
store_read_set(ps, id);
/* Both the create APIs can return NULL if used in their default mode
* (because there is no other way of handling an error because the jmp_buf by
* default is stored in png_struct and that has not been allocated!)
* However, given that store_error works correctly in these circumstances we
* don't ever expect NULL in this program.
*/
if (ps->speed)
ps->pread = png_create_read_struct(PNG_LIBPNG_VER_STRING, ps,
store_error, store_warning);
else
ps->pread = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, ps,
store_error, store_warning, &ps->read_memory_pool, store_malloc,
store_free);
if (ppi != NULL)
*ppi = ps->piread = png_create_info_struct(ps->pread);
if (ps->pread == NULL)
{
struct exception_context *the_exception_context = &ps->exception_context;
result = ps->pread;
}
++(ps->nerrors);
fprintf(stderr, "%s: png_create_read_struct returned NULL (unexpected)\n",
ps->test);
Catch(fault)
{
if (ps != fault) Throw fault;
Throw ps;
}
store_read_set(ps, id);
return result;
if (ppi != NULL)
*ppi = ps->piread = png_create_info_struct(ps->pread);
return ps->pread;
}
/* The overall cleanup of a store simply calls the above then removes all the
......@@ -1443,34 +1446,21 @@ static png_structp
set_modifier_for_read(png_modifier *pm, png_infopp ppi, png_uint_32 id,
PNG_CONST char *name)
{
volatile png_structp ppSafe = set_store_for_read(&pm->this, ppi, id, name);
if (ppSafe != NULL)
{
context(&pm->this, fault);
Try
{
pm->state = modifier_start;
pm->bit_depth = 0;
pm->colour_type = 255;
pm->pending_len = 0;
pm->pending_chunk = 0;
pm->flush = 0;
pm->buffer_count = 0;
pm->buffer_position = 0;
}
/* Do this first so that the modifier fields are cleared even if an error
* happens allocating the png_struct. No allocation is done here so no
* cleanup is required.
*/
pm->state = modifier_start;
pm->bit_depth = 0;
pm->colour_type = 255;
Catch(fault)
{
store_read_reset(&pm->this);
if (fault != &pm->this) Throw fault;
return NULL;
}
}
pm->pending_len = 0;
pm->pending_chunk = 0;
pm->flush = 0;
pm->buffer_count = 0;
pm->buffer_position = 0;
return ppSafe;
return set_store_for_read(&pm->this, ppi, id, name);
}
/***************************** STANDARD PNG FILES *****************************/
......@@ -2031,17 +2021,12 @@ standard_test(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type,
size_t cbRow;
int npasses;
/* Get a png_struct for writing the image. */
/* Get a png_struct for writing the image, this will throw an error if it
* fails, so we don't need to check the result.
*/
pp = set_store_for_read(ps, &pi,
FILEID(colour_type, bit_depth, interlace_type), "standard");
/* 'return' from within a Try block is not permitted, so use a bare Throw
* to get to the Catch block: set_store_for_read has already handled the
* error.
*/
if (pp == NULL)
Throw ps;
/* Introduce the correct read function. */
png_set_read_fn(ps->pread, ps, store_read);
......@@ -2394,15 +2379,10 @@ gamma_test(png_modifier *pm, PNG_CONST png_byte colour_type,
modification_reset(pm->modifications);
/* Get a png_struct for writing the image, if this fails just given up by
* doing a Throw to get to the Catch below.
*/
/* Get a png_struct for writing the image. */
pp = set_modifier_for_read(pm, &pi, FILEID(colour_type, bit_depth,
interlace_type), name);
if (pp == NULL)
Throw &pm->this;
/* Se the correct read function. */
png_set_read_fn(pp, pm, modifier_read);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册