mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[libpng17] Fixed GCC unsigned int->float warnings. Various versions of GCC
seem to generate warnings when an unsigned value is implicitly
converted to double. This is probably a GCC bug but this change
avoids the issue by explicitly converting to (int) where safe.
Free all allocated memory in pngimage. The file buffer cache was left
allocated at the end of the program, harmless but it causes memory
leak reports from clang.
Fixed array size calculations to avoid warnings. At various points
in the code the number of elements in an array is calculated using
sizeof. This generates a compile time constant of type (size_t) which
is then typically assigned to an (unsigned int) or (int). Some versions
of GCC on 64-bit systems warn about the apparent narrowing, even though
the same compiler does apparently generate the correct, in-range,
numeric constant. This adds appropriate, safe, casts to make the
warnings go away.
This commit is contained in:
committed by
Glenn Randers-Pehrson
parent
41547820e8
commit
f87df31c8c
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user