为什么ZLIB解压缩?

时间:2013-09-11 17:45:23

标签: c++ c zlib

我正在将ZLIB直接编译成可执行文件,正在VS2010上编译 - 64位,这个简单的程序总是挂起,有什么想法吗?更多信息如下:

调用堆栈:

zlibtest.exe!inflate(z_stream_s * strm, int flush)  Line 607    

zlibtest.exe!uncompress(unsigned char * dest, unsigned long * destLen, const unsigned char * source, unsigned long sourceLen)  Line 44

zlibtest.exe!main(int argc, char * * argv)  Line 137 

它挂在这里:

for (;;)
    switch (state->mode) {
    case HEAD:
        if (state->wrap == 0) {
            state->mode = TYPEDO;
            break;
        }
        **NEEDBITS(16);**

程序:

#include "zlib.h"

int main( int argc, char * argv[] )
{
    char * buffer = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
    ULONG buffer_size = strlen( buffer ) + 1;

    ULONG compressed_size = compressBound( buffer_size );
    BYTE * compressed_buffer = new BYTE[ compressed_size ];

    if ( Z_OK != compress2( compressed_buffer, &compressed_size, ( Bytef * ) buffer, buffer_size, Z_DEFAULT_COMPRESSION ) )
        printf( "Failed to compress." );

    ULONG uncompressed_size = buffer_size;
    BYTE * uncompressed_buffer = new BYTE[ uncompressed_size ];

    if ( Z_OK != uncompress( uncompressed_buffer, &uncompressed_size, compressed_buffer, compressed_size ) )
        printf( "Failed to uncompress" );

    printf( "Press <ENTER> to exit..." );
    std::cin.ignore();
}

0 个答案:

没有答案