MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / stbi__zexpand

Function stbi__zexpand

Source/Utils/stb_image.h:4272–4292  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4270}
4271
4272static int stbi__zexpand(stbi__zbuf *z, char *zout, int n) // need to make room for n bytes
4273{
4274 char *q;
4275 unsigned int cur, limit, old_limit;
4276 z->zout = zout;
4277 if (!z->z_expandable) return stbi__err("output buffer limit","Corrupt PNG");
4278 cur = (unsigned int) (z->zout - z->zout_start);
4279 limit = old_limit = (unsigned) (z->zout_end - z->zout_start);
4280 if (UINT_MAX - cur < (unsigned) n) return stbi__err("outofmem", "Out of memory");
4281 while (cur + n > limit) {
4282 if(limit > UINT_MAX / 2) return stbi__err("outofmem", "Out of memory");
4283 limit *= 2;
4284 }
4285 q = (char *) STBI_REALLOC_SIZED(z->zout_start, old_limit, limit);
4286 STBI_NOTUSED(old_limit);
4287 if (q == NULL) return stbi__err("outofmem", "Out of memory");
4288 z->zout_start = q;
4289 z->zout = q + cur;
4290 z->zout_end = q + limit;
4291 return 1;
4292}
4293
4294static const int stbi__zlength_base[31] = {
4295 3,4,5,6,7,8,9,10,11,13,

Callers 2

Calls 1

stbi__errFunction · 0.85

Tested by

no test coverage detected