Merge branch 'master' of git://github.com/teeworlds/teeworlds

This commit is contained in:
SushiTee 2012-08-11 16:28:12 +02:00
commit b10931eb9d
2 changed files with 39 additions and 6 deletions

View file

@ -150,6 +150,7 @@ static int png_get_bpp(png_t* png)
static int png_read_ihdr(png_t* png) static int png_read_ihdr(png_t* png)
{ {
int result;
unsigned length; unsigned length;
#if DO_CRC_CHECKS #if DO_CRC_CHECKS
unsigned orig_crc; unsigned orig_crc;
@ -168,7 +169,9 @@ static int png_read_ihdr(png_t* png)
if(file_read(png, ihdr, 1, 13+4) != 13+4) if(file_read(png, ihdr, 1, 13+4) != 13+4)
return PNG_EOF_ERROR; return PNG_EOF_ERROR;
#if DO_CRC_CHECKS #if DO_CRC_CHECKS
file_read_ul(png, &orig_crc); result = file_read_ul(png, &orig_crc);
if(result != PNG_NO_ERROR)
return result;
calc_crc = crc32(0L, 0, 0); calc_crc = crc32(0L, 0, 0);
calc_crc = crc32(calc_crc, ihdr, 13+4); calc_crc = crc32(calc_crc, ihdr, 13+4);
@ -176,7 +179,9 @@ static int png_read_ihdr(png_t* png)
if(orig_crc != calc_crc) if(orig_crc != calc_crc)
return PNG_CRC_ERROR; return PNG_CRC_ERROR;
#else #else
file_read_ul(png); result = file_read_ul(png);
if(result != PNG_NO_ERROR)
return result;
#endif #endif
png->width = get_ul(ihdr+4); png->width = get_ul(ihdr+4);
@ -275,6 +280,8 @@ int png_open_read(png_t* png, png_read_callback_t read_fun, void* user_pointer)
result = png_read_ihdr(png); result = png_read_ihdr(png);
png->bpp = (unsigned char)png_get_bpp(png); png->bpp = (unsigned char)png_get_bpp(png);
if(png->bpp < 0)
result = png->bpp;
return result; return result;
} }
@ -392,6 +399,7 @@ static int png_end_deflate(png_t* png)
deflateEnd(stream); deflateEnd(stream);
png_free(png->zs); png_free(png->zs);
png->zs = 0;
return PNG_NO_ERROR; return PNG_NO_ERROR;
} }
@ -418,6 +426,7 @@ static int png_end_inflate(png_t* png)
} }
png_free(png->zs); png_free(png->zs);
png->zs = 0;
return PNG_NO_ERROR; return PNG_NO_ERROR;
} }
@ -527,6 +536,8 @@ static int png_read_idat(png_t* png, unsigned firstlen)
#endif #endif
chunk = png_alloc(firstlen); chunk = png_alloc(firstlen);
if(!chunk)
return PNG_MEMORY_ERROR;
result = png_init_inflate(png); result = png_init_inflate(png);
@ -572,6 +583,11 @@ static int png_read_idat(png_t* png, unsigned firstlen)
{ {
png_free(chunk); png_free(chunk);
chunk = png_alloc(length); chunk = png_alloc(length);
if(!chunk)
{
png_end_inflate(png);
return PNG_MEMORY_ERROR;
}
old_len = length; old_len = length;
} }
@ -604,9 +620,14 @@ static int png_process_chunk(png_t* png)
return PNG_FILE_ERROR; return PNG_FILE_ERROR;
if(type == *(unsigned int*)"IDAT") /* if we found an idat, all other idats should be followed with no other chunks in between */ if(type == *(unsigned int*)"IDAT") /* if we found an idat, all other idats should be followed with no other chunks in between */
{
if(!png->png_data)
{ {
png->png_datalen = png->width * png->height * png->bpp + png->height; png->png_datalen = png->width * png->height * png->bpp + png->height;
png->png_data = png_alloc(png->png_datalen); png->png_data = png_alloc(png->png_datalen);
}
else
return PNG_FILE_ERROR;
if(!png->png_data) if(!png->png_data)
return PNG_MEMORY_ERROR; return PNG_MEMORY_ERROR;
@ -797,6 +818,8 @@ static int png_unfilter(png_t* png, unsigned char* data)
int png_get_data(png_t* png, unsigned char* data) int png_get_data(png_t* png, unsigned char* data)
{ {
int result = PNG_NO_ERROR; int result = PNG_NO_ERROR;
png->png_data = 0;
png->zs = 0;
while(result == PNG_NO_ERROR) while(result == PNG_NO_ERROR)
{ {
@ -804,14 +827,19 @@ int png_get_data(png_t* png, unsigned char* data)
} }
if(result != PNG_DONE) if(result != PNG_DONE)
{
if(!png->png_data)
{ {
png_free(png->png_data); png_free(png->png_data);
png->png_data = 0;
}
return result; return result;
} }
result = png_unfilter(png, data); result = png_unfilter(png, data);
png_free(png->png_data); png_free(png->png_data);
png->png_data = 0;
return result; return result;
} }

View file

@ -24,6 +24,11 @@
daniel.karling@gmail.com daniel.karling@gmail.com
*/ */
/*
NOTICE:
This is a modified version which contains changes that address
compiler warnings and increase stability.
*/
#ifndef _PNGLITE_H_ #ifndef _PNGLITE_H_
#define _PNGLITE_H_ #define _PNGLITE_H_