mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[master] Imported from libpng-1.6.15.tar
This commit is contained in:
@@ -337,6 +337,9 @@ validate_T(void)
|
||||
* In both cases the file data is held in a linked list of buffers - not all
|
||||
* of these are in use at any time.
|
||||
*/
|
||||
#define NEW(type) ((type *)malloc(sizeof (type)))
|
||||
#define DELETE(ptr) (free(ptr))
|
||||
|
||||
struct buffer_list
|
||||
{
|
||||
struct buffer_list *next; /* next buffer in list */
|
||||
@@ -361,6 +364,25 @@ buffer_init(struct buffer *buffer)
|
||||
buffer->current = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
buffer_destroy_list(struct buffer_list *list)
|
||||
{
|
||||
if (list != NULL)
|
||||
{
|
||||
struct buffer_list *next = list->next;
|
||||
DELETE(list);
|
||||
buffer_destroy_list(next);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
buffer_destroy(struct buffer *buffer)
|
||||
{
|
||||
struct buffer_list *list = buffer->first.next;
|
||||
buffer_init(buffer);
|
||||
buffer_destroy_list(list);
|
||||
}
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
static void
|
||||
buffer_start_write(struct buffer *buffer)
|
||||
@@ -390,8 +412,6 @@ get_buffer(png_structp pp)
|
||||
return (struct buffer*)png_get_io_ptr(pp);
|
||||
}
|
||||
|
||||
#define NEW(type) ((type *)malloc(sizeof (type)))
|
||||
|
||||
static struct buffer_list *
|
||||
buffer_extend(struct buffer_list *current)
|
||||
{
|
||||
@@ -598,6 +618,17 @@ display_clean(struct display *dp)
|
||||
dp->results = 0; /* reset for next time */
|
||||
}
|
||||
|
||||
static void
|
||||
display_destroy(struct display *dp)
|
||||
{
|
||||
/* Release any memory held in the display. */
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
buffer_destroy(&dp->written_file);
|
||||
# endif
|
||||
|
||||
buffer_destroy(&dp->original_file);
|
||||
}
|
||||
|
||||
static struct display *
|
||||
get_dp(png_structp pp)
|
||||
/* The display pointer is always stored in the png_struct error pointer */
|
||||
@@ -1605,6 +1636,9 @@ main(const int argc, const char * const * const argv)
|
||||
display_clean(&d);
|
||||
}
|
||||
|
||||
/* Release allocated memory */
|
||||
display_destroy(&d);
|
||||
|
||||
return errors != 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +157,13 @@ define_exception_type(struct png_store*);
|
||||
&(ps)->exception_context
|
||||
#define context(ps,fault) anon_context(ps); png_store *fault
|
||||
|
||||
/* This macro returns the number of elements in an array as an (unsigned int),
|
||||
* it is necessary to avoid the inability of certain versions of GCC to use
|
||||
* the value of a compile-time constant when performing range checks. It must
|
||||
* be passed an array name.
|
||||
*/
|
||||
#define ARRAY_SIZE(a) ((unsigned int)((sizeof (a))/(sizeof (a)[0])))
|
||||
|
||||
/******************************* UTILITIES ************************************/
|
||||
/* Error handling is particularly problematic in production code - error
|
||||
* handlers often themselves have bugs which lead to programs that detect
|
||||
@@ -1558,7 +1565,7 @@ set_store_for_write(png_store *ps, png_infopp ppi,
|
||||
|
||||
else
|
||||
# endif
|
||||
ps->pwrite = png_create_write_struct(PNG_LIBPNG_VER_STRING,
|
||||
ps->pwrite = png_create_write_struct(png_get_libpng_ver(NULL),
|
||||
ps, store_error, store_warning);
|
||||
|
||||
png_set_write_fn(ps->pwrite, ps, store_write, store_flush);
|
||||
@@ -4106,7 +4113,7 @@ make_errors(png_modifier* PNG_CONST pm, png_byte PNG_CONST colour_type,
|
||||
standard_name(name, sizeof name, 0, colour_type, 1<<bdlo, 0,
|
||||
interlace_type, 0, 0, 0);
|
||||
|
||||
for (test=0; test<(sizeof error_test)/(sizeof error_test[0]); ++test)
|
||||
for (test=0; test<ARRAY_SIZE(error_test); ++test)
|
||||
{
|
||||
make_error(&pm->this, colour_type, DEPTH(bdlo), interlace_type,
|
||||
test, name);
|
||||
@@ -10098,12 +10105,12 @@ int main(int argc, char **argv)
|
||||
|
||||
/* Store the test gammas */
|
||||
pm.gammas = gammas;
|
||||
pm.ngammas = (sizeof gammas) / (sizeof gammas[0]);
|
||||
pm.ngammas = ARRAY_SIZE(gammas);
|
||||
pm.ngamma_tests = 0; /* default to off */
|
||||
|
||||
/* And the test encodings */
|
||||
pm.encodings = test_encodings;
|
||||
pm.nencodings = (sizeof test_encodings) / (sizeof test_encodings[0]);
|
||||
pm.nencodings = ARRAY_SIZE(test_encodings);
|
||||
|
||||
pm.sbitlow = 8U; /* because libpng doesn't do sBIT below 8! */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user