0

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?

Manjoor
  • 4,091
  • 10
  • 43
  • 67
  • Have you checked what malloc() returns? It might return a null pointer. – sharptooth Mar 10 '10 at 08:52
  • Also have you tried to dump all the parameters you pass into decompress() to the console? Maybe some of them have unreasonable values fro whatever reason. – sharptooth Mar 10 '10 at 08:54
  • What happened to the 2nd argument? It used to be a pointer. – Hans Passant Mar 10 '10 at 09:01
  • @sharptooth The code above is for test purpose only so there is no any error checking. I can see in my debugger that everything goes fine. It is just giveing error on last line. The code successfully read file allocate input and output buffer. set input length and set output length to 0. – Manjoor Mar 10 '10 at 09:15
  • @nobugz If yoou are reffering to my previous post, this is another function defined in lzo.h – Manjoor Mar 10 '10 at 09:17
  • And what does that mean??? No doubt it is an awesome library without a single working example.. – Manjoor Mar 10 '10 at 12:52
  • There is an example called simple.c: http://www.fullsack.com/gnnix/base/root/dist/usr/src/lzo-1.08/examples/simple.c – HostileFork says dont trust SE Mar 10 '10 at 15:18

2 Answers2

0

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/

Community
  • 1
  • 1
  • i_len is initialize with 280. My input data is 280 bytes. I can see in debugger that it is initializing perfectly. See edited code code i have added lzo_memset to initialize o_burff – Manjoor Mar 10 '10 at 09:42
  • Oops, I didn't notice the scroll bar on your code sample, thus thinking it ended before the fread. (I hate it when inner panels are fixed size and have their own scroll bars independent of the page's scroll bar!) Updated. – HostileFork says dont trust SE Mar 10 '10 at 15:27
-1

Thans everyone for suggestion and comments.

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

Manjoor
  • 4,091
  • 10
  • 43
  • 67