在 c++ 中使用 lzo 库应用

发布于 2024-08-25 02:42:44 字数 1626 浏览 6 评论 0原文

我有 lzo 库可以在我们的应用程序中使用。提供的版本是1.07。 他们给了我 .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 */ );

什么问题吗?

I got lzo library to use in our application. The version was provided is 1.07.
They have given me .lib along with some header file and some .c source files.

I have setup test environment as per specs. I am able to see lzo routine functions in my application.

Here is my test application

#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;   
}

It gives access violation on last line.

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

in provided library signature for above functiion is

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

What is wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡淡離愁欲言轉身 2024-09-01 02:42:44

您确定 512 字节对于解压数据来说足够大吗?您不应该使用任意值,而是应该在压缩文件时将原始大小作为标头存放在某处:

LZO 解压缩缓冲区大小

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

除此之外,它是开源的。那么为什么不构建带有调试信息的 lzo 并进入其中查看问题出在哪里呢?

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

Are you sure 512 bytes is big enough for the decompressed data? You shouldn't be using an arbitrary value, but rather you should have stowed away the original size somewhere as a header when your file was compressed:

LZO Decompression Buffer Size

You should probably make your data types match the interface spec (e.g. o_len should be a lzo_uint...you're passing an address so the actual underlying type matters).

Beyond that, it's open source. So why don't you build lzo with debug info and step into it to see where the problem is?

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

少跟Wǒ拽 2024-09-01 02:42:44

感谢大家的建议和意见。

问题出在数据上。我已经解压成功了。

Thans everyone for suggestion and comments.

The problem was with data. I have successfully decomressed it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文