[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gnulib] getgroups minor cleanup for signature, errno preserving
From: |
Paul Eggert |
Subject: |
[Bug-gnulib] getgroups minor cleanup for signature, errno preserving |
Date: |
16 Oct 2003 00:38:22 -0700 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
While trolling for address-calculation bugs I noticed that getgroups
is probably immune, but it has a couple of other minor bugs. It needs
to include <stdlib.h> to declare 'free', and it needs to watch out for
'free' mangling the errno. I installed this patch, which also adds a
comment as to why we don't need to worry about address calculation
overflow.
2003-10-16 Paul Eggert <address@hidden>
* getgroups.c: Include <errno.h>, <stdlib.h>.
(getgroups): First arg is int, not size_t.
Don't let 'free' mangle errno.
Index: getgroups.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/getgroups.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -p -u -r1.7 -r1.8
--- getgroups.c 5 Aug 2003 05:29:41 -0000 1.7
+++ getgroups.c 16 Oct 2003 07:30:56 -0000 1.8
@@ -20,6 +20,8 @@
#include <config.h>
#include <stdio.h>
#include <sys/types.h>
+#include <errno.h>
+#include <stdlib.h>
#include "xalloc.h"
@@ -29,10 +31,11 @@
provided function handle all others. */
int
-getgroups (size_t n, GETGROUPS_T *group)
+getgroups (int n, GETGROUPS_T *group)
{
int n_groups;
GETGROUPS_T *gbuf;
+ int saved_errno;
#undef getgroups
@@ -43,6 +46,9 @@ getgroups (size_t n, GETGROUPS_T *group)
gbuf = NULL;
while (1)
{
+ /* No need to worry about address arithmetic overflow here,
+ since the ancient systems that we're running on have low
+ limits on the number of secondary groups. */
gbuf = xrealloc (gbuf, n * sizeof (GETGROUPS_T));
n_groups = getgroups (n, gbuf);
if (n_groups < n)
@@ -50,7 +56,9 @@ getgroups (size_t n, GETGROUPS_T *group)
n += 10;
}
+ saved_errno = errno;
free (gbuf);
+ errno = saved_errno;
return n_groups;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug-gnulib] getgroups minor cleanup for signature, errno preserving,
Paul Eggert <=