使用的是vs2015,zlib1.2.8
使用相同的参数运行inflateHTTPGzip函数返回的不同结果:
- 1.inflate 函数返回-3
- 2.解压结果长度小于正确长度(只正确解压一部分数据)
- 3.正常运行,结果正确
请各位前辈帮我看看是哪里出了问题
int inflateHTTPGzip(void * dest, unsigned long destLen, void * src, unsigned long srcLen, unsigned long * outputLen) {
char * pDest = (char *)dest;
char * pStart = NULL;
char * ptr = (char *)src;
unsigned long size = 0ul;
pStart = strstr((char*)src, "\r\n\r\n");
if (!pStart) {
return INVALID_STRING;
}
pStart += 4;
if (sscanf_s((char*)pStart, "%x", &size) != 1) {
return INVALID_STRING;
}
pStart = strstr((char*)pStart, "\r\n");
if (!pStart) {
return INVALID_STRING;
}
pStart += 2;
z_stream d_stream ;
ZeroMemory(&d_stream, sizeof(z_stream));
d_stream.avail_in = size;
d_stream.next_in = (unsigned char *)pStart;
d_stream.avail_out = destLen;
d_stream.next_out = (unsigned char *)dest;
int err = 0;
if ((err = inflateInit2(&d_stream, 47)) != Z_OK) {
return ZLIB_ERROR;
}
if ((err = inflate(&d_stream, Z_NO_FLUSH)) != Z_STREAM_END ){
return ZLIB_ERROR;
}
if ((err = inflateEnd(&d_stream)) != Z_OK) {
return ZLIB_ERROR;
}
*outputLen = d_stream.total_out;
return SUCCESS;
}