emacs-devel
[Top][All Lists]
Advanced

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

Re: trunk r113804: * decompress.c: Fix bugs with large buffers and weird


From: Lars Magne Ingebrigtsen
Subject: Re: trunk r113804: * decompress.c: Fix bugs with large buffers and weird inputs.
Date: Tue, 13 Aug 2013 18:21:09 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Lars Magne Ingebrigtsen <address@hidden> writes:

> I think writing 1 << 14 and then checking whether that's larger than
> UINT_MAX is still pretty unclear.  My first thought, at least, was
> "geez, he's making a HUGE buffer gap", until I started doing the math.

Here's the current code, abbreviated:

      /* Maximum number of bytes that one 'inflate' call should read and write.
         Do not make avail_out too large, as that might unduly delay C-g.
         In any case zlib requires that these values not exceed UINT_MAX.  */
      enum { avail_out = 1 << 14 };
      verify (avail_out <= UINT_MAX);

      ptrdiff_t decompressed;

      if (GAP_SIZE < avail_out)
        make_gap (avail_out - GAP_SIZE);
      stream.avail_out = avail_out;
      decompressed = avail_out - stream.avail_out;

I think it's pretty opaque.  What's with all the ptrdiff_t's when
inflate only takes ints, anyway?  And checking whether a constant is
larger than UINT_MAX is the thing that makes me go "wha?  Is there
something clever going on here that I don't understand?"

So why not do it simple and nice:

      /* Maximum number of bytes that one 'inflate' call should read and write.
         Do not make buffer_size too large, as that might unduly delay C-g.  */
      int decompressed, buffer_size = 16384;

      if (GAP_SIZE < buffer_size)
        make_gap (buffer_size - GAP_SIZE);
      stream.avail_out = buffer_size;
      decompressed = buffer_size - stream.avail_out;

No odd constants, checks or explanations necessary.

Although this may violate the new apparent dictum that at least every
three lines need to compare with UINT_MAX, which seems to be the coding
standard lately.  >"?

-- 
(domestic pets only, the antidote for overdose, milk.)
  No Gnus T-Shirt for sale: http://ingebrigtsen.no/no.php
  and http://lars.ingebrigtsen.no/2013/08/twenty-years-of-september.html



reply via email to

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