[libpng17] Imported from libpng-1.7.0beta55.tar

This commit is contained in:
Glenn Randers-Pehrson
2015-03-09 08:29:24 -05:00
parent c062330846
commit 0fba15c567
18 changed files with 1710 additions and 1032 deletions

View File

@@ -49,18 +49,42 @@ png_read_data(png_structrp png_ptr, png_bytep data, png_size_t length)
void PNGCBAPI
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_size_t check;
png_FILE_p io_ptr;
if (png_ptr == NULL)
return;
io_ptr = png_get_io_ptr(png_ptr);
/* fread() returns 0 on error, so it is OK to store this in a png_size_t
if (length == 0)
png_error(png_ptr, "Read Error: invalid length requested");
clearerr(io_ptr);
if (fileno(io_ptr) == -1)
png_error(png_ptr, "Read Error: invalid io_ptr");
/*
* fread() returns 0 on error, so it is OK to store this in a png_size_t
* instead of an int, which is what fread() actually returns.
*/
check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr));
if ((png_size_t)fread((void *)data, sizeof (png_byte), length,
io_ptr) != length)
{
clearerr(io_ptr);
png_error(png_ptr, "Read Error: invalid length returned");
}
if (check != length)
png_error(png_ptr, "Read Error");
if (ferror(io_ptr))
{
clearerr(io_ptr);
png_error(png_ptr, "Read Error: error returned by fread()");
}
if (feof(io_ptr))
{
clearerr(io_ptr);
png_error(png_ptr, "Read Error: unexpected end of file");
}
clearerr(io_ptr);
}
#endif