summary refs log tree commit diff
path: root/hurd/alloc-fd.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1995-05-12 00:50:29 +0000
committerRoland McGrath <roland@gnu.org>1995-05-12 00:50:29 +0000
commit5f5ab9533be2ac2e223e1b8399346e254c52e18e (patch)
treee6f446e268d8ea594d618333f7f390ba4b718e7c /hurd/alloc-fd.c
parent63deb0e4e7fc6ed90e8666646a813761afb97520 (diff)
downloadglibc-5f5ab9533be2ac2e223e1b8399346e254c52e18e.tar.gz
glibc-5f5ab9533be2ac2e223e1b8399346e254c52e18e.tar.xz
glibc-5f5ab9533be2ac2e223e1b8399346e254c52e18e.zip
(_hurd_alloc_fd): When expanding the dtable, make sure the new size exceeds FIRST_FD.
Diffstat (limited to 'hurd/alloc-fd.c')
-rw-r--r--hurd/alloc-fd.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/hurd/alloc-fd.c b/hurd/alloc-fd.c
index 02a1bdfd52..e83618ac4b 100644
--- a/hurd/alloc-fd.c
+++ b/hurd/alloc-fd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1994 Free Software Foundation, Inc.
+/* Copyright (C) 1994, 1995 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
 
 The GNU C Library is free software; you can redistribute it and/or
@@ -89,17 +89,20 @@ _hurd_alloc_fd (int *fd, int first_fd)
 	  /* Enlarge the table.  */
 	  int save = errno;
 	  struct hurd_fd **new;
-	  /* Try to double the table size (but don't exceed the limit).
-	     If there isn't any at all, give it three slots (because
-	     stdio will take that many anyway).  */
-	  int size = _hurd_dtablesize ? _hurd_dtablesize * 2 : 3;
+	  /* Try to double the table size, but don't exceed the limit,
+	     and make sure it exceeds FIRST_FD.  */
+	  int size = _hurd_dtablesize * 2;
 	  if (size > rlimit)
 	    size = rlimit;
+	  else if (size <= first_fd)
+	    size = first_fd + 1;
+
 	  /* If we fail to allocate that, decrement the desired size
 	     until we succeed in allocating it.  */
 	  do
 	    new = realloc (_hurd_dtable, size * sizeof (*_hurd_dtable));
-	  while (new == NULL && size-- > _hurd_dtablesize);
+	  while (new == NULL && size-- > first_fd);
+
 	  if (new != NULL)
 	    {
 	      /* We managed to allocate a new table.  Now install it.  */