代码之家  ›  专栏  ›  技术社区  ›  Manjoor

在c++应用程序中使用lzo库

  •  0
  • Manjoor  · 技术社区  · 16 年前

    他们给了我.lib以及一些头文件和一些.c源文件。

    我已经按照规范设置了测试环境。我可以在应用程序中看到lzo例程函数。

    这是我的测试申请表

    #include "stdafx.h"
    #include "lzoconf.h"
    #include "lzo1z.h"
    #include <stdlib.h>
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        FILE * pFile;
        long lSize;
        unsigned char *i_buff;
        unsigned char *o_buff;
    
        int i_len,e = 0;
        unsigned int o_len;
    
        size_t result;
    
        //data.txt have a single compressed packet 
        pFile = fopen("data.txt","rb");
    
        if (pFile==NULL) 
            return -1;
    
        // obtain file size:
        fseek (pFile , 0 , SEEK_END);
        lSize = ftell (pFile);
        rewind (pFile);
    
        // allocate memory to contain the whole file:
        i_buff = (unsigned char*) malloc (sizeof(char)*lSize);
        if (i_buff == NULL) 
            return -1;
    
        // copy the file into the buffer:
        result = fread (i_buff,1,lSize,pFile);
        if (result != lSize) 
            return -1;
    
        i_len = lSize;
        o_len = 512;
    
        // allocate memory for output buffer
        o_buff = (unsigned char*) malloc(sizeof(char)*o_len);
    
        if (o_buff == NULL) 
            return -1;
         lzo_memset(o_buff,0,o_len);    
        lzo1z_decompress(i_buff,i_len,o_buff,&o_len,NULL);
    
        return 0;   
    }
    

    它在最后一行给出了访问冲突。

    lzo1z_decompress(i_buff,i_len,o_buff,&o_len,NULL);
    

    在提供的库中,上述功能的签名是

    lzo1z_decompress        ( const lzo_byte *src, lzo_uint  src_len,
                                    lzo_byte *dst, lzo_uint *dst_len,
                                    lzo_voidp wrkmem /* NOT USED */ );
    

    怎么了?

    2 回复  |  直到 16 年前
        1
  •  0
  •   Community Mohan Dere    9 年前

    您确定512字节对于解压缩的数据足够大吗?您不应该使用任意值,而是应该在压缩文件时将原始大小隐藏在某个地方作为头:

    LZO Decompression Buffer Size

    您可能应该使数据类型与接口规范相匹配(例如。 o_len lzo_uint …您正在传递一个地址,因此实际的底层类型很重要)。

    除此之外,它是开源的。那么,为什么不使用调试信息构建lzo,并深入了解问题所在呢?

    http://www.oberhumer.com/opensource/lzo/

        2
  •  -1
  •   Manjoor    16 年前

    谢谢大家的建议和评论。

    问题出在数据上。我成功地把它拆开了。

    推荐文章