This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
off-by-one problem in dtable.cc?
- From: Joe Buehler <jbuehler at hekimian dot com>
- To: cygwin at cygwin dot com
- Date: Mon, 24 Jun 2002 16:00:55 -0400
- Subject: off-by-one problem in dtable.cc?
- Newsgroups: gmane.os.cygwin
The following code in dtable::dup2() determines whether the fd table
should be expanded, and how much
if ((size_t) newfd >= size)
{
int inc_size = NOFILE_INCR * ((newfd + NOFILE_INCR - 1) / NOFILE_INCR) -
size;
extend (inc_size);
}
Consider:
NOFILE_INCR is #defined to be 32. If size is 32, and newfd is 32, then
inc_size will be: 32 * ((32 + 32 - 1) / 32) - 32 == 0, so the fdtable
will not be expanded, and interesting things will undoubtedly ensue!
I think it should be:
if ((size_t) newfd >= size)
{
int inc_size = NOFILE_INCR * (newfd / NOFILE_INCR + 1) - size;
extend (inc_size);
}
Joe Buehler
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/