MCPcopy Create free account
hub / github.com/assaultcube/AC / getgzbuf

Function getgzbuf

source/src/protocol.cpp:213–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211}
212
213ucharbuf *getgzbuf(ucharbuf &p) // fetch a gzipped buffer; needs to be freed properly later
214{
215 int size = getuint(p);
216 int sizegz = getuint(p);
217 if(sizegz == 0) sizegz = size; // uncompressed was smaller
218 if(sizegz > 0 && p.remaining() >= sizegz && sizegz <= MAXGZMSGSIZE && size >= 0 && size <= MAXGZMSGSIZE)
219 {
220 uchar *data = new uchar[size + 1];
221 uLongf rawsize = size;
222 if(data)
223 {
224 if(size == sizegz)
225 {
226 memcpy(data, &p.buf[p.len], size);
227 }
228 else if(uncompress(data, &rawsize, &p.buf[p.len], sizegz) != Z_OK || rawsize - size != 0)
229 {
230 p.forceoverread();
231 delete[] data;
232 return NULL;
233 }
234 p.len += sizegz;
235 return new ucharbuf(data, size);
236 }
237 }
238 p.forceoverread();
239 return NULL;
240}
241
242void freegzbuf(ucharbuf *p) // free a ucharbuf created by getgzbuf()
243{

Callers 2

parsemessagesFunction · 0.85
processFunction · 0.85

Calls 3

getuintFunction · 0.85
forceoverreadMethod · 0.80
remainingMethod · 0.45

Tested by

no test coverage detected