|
|
|
@ -621,18 +621,22 @@ typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1]; |
|
|
|
|
#define stbi_lrot(x,y) (((x) << (y)) | ((x) >> (32 - (y)))) |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(STBI_MALLOC) && defined(STBI_FREE) && defined(STBI_REALLOC) |
|
|
|
|
#if defined(STBI_MALLOC) && defined(STBI_FREE) && (defined(STBI_REALLOC) || defined(STBI_REALLOC_SIZED)) |
|
|
|
|
// ok
|
|
|
|
|
#elif !defined(STBI_MALLOC) && !defined(STBI_FREE) && !defined(STBI_REALLOC) |
|
|
|
|
#elif !defined(STBI_MALLOC) && !defined(STBI_FREE) && !defined(STBI_REALLOC) && !defined(STBI_REALLOC_SIZED) |
|
|
|
|
// ok
|
|
|
|
|
#else |
|
|
|
|
#error "Must define all or none of STBI_MALLOC, STBI_FREE, and STBI_REALLOC." |
|
|
|
|
#error "Must define all or none of STBI_MALLOC, STBI_FREE, and STBI_REALLOC (or STBI_REALLOC_SIZED)." |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifndef STBI_MALLOC |
|
|
|
|
#define STBI_MALLOC(sz) malloc(sz) |
|
|
|
|
#define STBI_REALLOC(p,oldsz,newsz) realloc(p,newsz) |
|
|
|
|
#define STBI_FREE(p) free(p) |
|
|
|
|
#define STBI_MALLOC(sz) malloc(sz) |
|
|
|
|
#define STBI_REALLOC(p,newsz) realloc(p,newsz) |
|
|
|
|
#define STBI_FREE(p) free(p) |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifndef STBI_REALLOC_SIZED |
|
|
|
|
#define STBI_REALLOC_SIZED(p,oldsz,newsz) STBI_REALLOC(p,newsz) |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// x86/x64 detection
|
|
|
|
@ -3615,7 +3619,7 @@ static int stbi__zexpand(stbi__zbuf *z, char *zout, int n) // need to make room |
|
|
|
|
limit = old_limit = (int) (z->zout_end - z->zout_start); |
|
|
|
|
while (cur + n > limit) |
|
|
|
|
limit *= 2; |
|
|
|
|
q = (char *) STBI_REALLOC(z->zout_start, old_limit, limit); |
|
|
|
|
q = (char *) STBI_REALLOC_SIZED(z->zout_start, old_limit, limit); |
|
|
|
|
if (q == NULL) return stbi__err("outofmem", "Out of memory"); |
|
|
|
|
z->zout_start = q; |
|
|
|
|
z->zout = q + cur; |
|
|
|
@ -4405,7 +4409,7 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp) |
|
|
|
|
if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096; |
|
|
|
|
while (ioff + c.length > idata_limit) |
|
|
|
|
idata_limit *= 2; |
|
|
|
|
p = (stbi_uc *) STBI_REALLOC(z->idata, idata_limit_old, idata_limit); if (p == NULL) return stbi__err("outofmem", "Out of memory"); |
|
|
|
|
p = (stbi_uc *) STBI_REALLOC_SIZED(z->idata, idata_limit_old, idata_limit); if (p == NULL) return stbi__err("outofmem", "Out of memory"); |
|
|
|
|
z->idata = p; |
|
|
|
|
} |
|
|
|
|
if (!stbi__getn(s, z->idata+ioff,c.length)) return stbi__err("outofdata","Corrupt PNG"); |
|
|
|
|