[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mysterious gzipped images

From: Paul Eggert
Subject: Re: Mysterious gzipped images
Date: Thu, 08 Aug 2013 06:22:12 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130803 Thunderbird/17.0.8

On 08/08/2013 03:35 AM, Lars Magne Ingebrigtsen wrote:

>   out = (char *) malloc (BUFFER_SIZE);

BUFFER_SIZE is so small that you should just put the buffer on the
stack "char out[BUFFER_SIZE];".  That way, you don't need to worry
about freeing it later (e.g., on error).

Or better yet, why not use the gap as the output buffer?
That should avoid some unnecessary copying.

>   stream.avail_in = iend - istart;

On 64-bit platforms, this won't work on buffers larger than 4 GiB.
I suggest 'stream.avail_in = min (iend - istart, UINT_MAX);'
and then put the whole thing inside a loop that repeats
until the input buffer is exhausted.

Each time through the inner loop, it should QUIT so that the user can
interrupt.  You need a record_unwind_protect around the whole thing;
the unwind-protect should be the code that deletes any uncompressed
data already inserted and restores point.

>     case Z_STREAM_ERROR:
>     case Z_NEED_DICT:
>     case Z_DATA_ERROR:
>     case Z_MEM_ERROR:

Shouldn't an error be signaled for this sort of thing?
That would fit in with the unwind-protect.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]