From: Lars Magne Ingebrigtsen <larsi@gnus.org>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: emacs-devel@gnu.org
Subject: Re: trunk r113804: * decompress.c: Fix bugs with large buffers and weird inputs.
Date: Tue, 13 Aug 2013 18:21:09 +0200 [thread overview]
Message-ID: <m338qdsgsq.fsf@stories.gnus.org> (raw)
In-Reply-To: <m3txit1va2.fsf@stories.gnus.org> (Lars Magne Ingebrigtsen's message of "Tue, 13 Aug 2013 17:10:29 +0200")
Lars Magne Ingebrigtsen <larsi@gnus.org> 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
next prev parent reply other threads:[~2013-08-13 16:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <E1V8elS-0003CG-7L@vcs.savannah.gnu.org>
2013-08-13 12:08 ` trunk r113804: * decompress.c: Fix bugs with large buffers and weird inputs Lars Magne Ingebrigtsen
2013-08-13 12:19 ` Andreas Schwab
2013-08-13 15:03 ` Paul Eggert
2013-08-13 15:10 ` Lars Magne Ingebrigtsen
2013-08-13 16:21 ` Lars Magne Ingebrigtsen [this message]
2013-08-13 21:47 ` Paul Eggert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m338qdsgsq.fsf@stories.gnus.org \
--to=larsi@gnus.org \
--cc=eggert@cs.ucla.edu \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.