[libpng16] Start-up code size improvements, error handler flexibility. These

changes alter how the tricky allocation of the initial png_struct and png_info
structures are handled. png_info is now handled in pretty much the same
way as everything else, except that the allocations handle NULL return
silently.  png_struct is changed in a similar way on allocation and on
deallocation a 'safety' error handler is put in place (which should never
be required).  The error handler itself is changed to permit mismatches
in the application and libpng error buffer size; however, this means a
silent change to the API to return the jmp_buf if the size doesn't match
the size from the libpng compilation; libpng now allocates the memory and
this may fail.  Overall these changes result in slight code size
reductions; however, this is a reduction in code that is always executed
so is particularly valuable.  Overall on a 64-bit system the libpng DLL
decreases in code size by 1733 bytes.  pngerror.o increases in size by
about 465 bytes because of the new functionality.
This commit is contained in:
John Bowler
2011-12-22 08:09:15 -06:00
committed by Glenn Randers-Pehrson
parent ad41b8838a
commit 40b2603687
13 changed files with 305 additions and 311 deletions

View File

@@ -1036,14 +1036,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
png_set_tIME(write_ptr, write_info_ptr, mod_time);
#ifdef PNG_TIME_RFC1123_SUPPORTED
/* We have to use memcpy instead of "=" because the string
* pointed to by png_convert_to_rfc1123() gets free'ed before
* we use it.
*/
memcpy(tIME_string, png_convert_to_rfc1123(read_ptr, mod_time),
png_sizeof(tIME_string));
if (png_convert_to_rfc1123_buffer(tIME_string, mod_time))
tIME_string[png_sizeof(tIME_string) - 1] = '\0';
else
strcpy(tIME_string, "*** invalid time ***");
tIME_string[png_sizeof(tIME_string) - 1] = '\0';
tIME_chunk_present++;
#endif /* PNG_TIME_RFC1123_SUPPORTED */
}
@@ -1231,13 +1229,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
#ifdef PNG_TIME_RFC1123_SUPPORTED
/* We have to use memcpy instead of "=" because the string
pointed to by png_convert_to_rfc1123() gets free'ed before
we use it */
memcpy(tIME_string, png_convert_to_rfc1123(read_ptr, mod_time),
png_sizeof(tIME_string));
if (png_convert_to_rfc1123_buffer(tIME_string, mod_time))
tIME_string[png_sizeof(tIME_string) - 1] = '\0';
else
strcpy(tIME_string, "*** invalid time ***");
tIME_string[png_sizeof(tIME_string) - 1] = '\0';
tIME_chunk_present++;
#endif /* PNG_TIME_RFC1123_SUPPORTED */
}