summaryrefslogtreecommitdiff
path: root/mg.c
diff options
context:
space:
mode:
authorSteve Peters <steve@fisharerojo.org>2005-12-26 17:29:13 +0000
committerSteve Peters <steve@fisharerojo.org>2005-12-26 17:29:13 +0000
commit757f63d8f908c08ca232cfc2d4d7d79164eb223e (patch)
tree6afd583c7335a5d903192c4b39f98e0b205acd04 /mg.c
parent599bf9a6a2d7541099ceb30e7475b9b3d98f6aa2 (diff)
downloadperl-757f63d8f908c08ca232cfc2d4d7d79164eb223e.tar.gz
In this, the last tale of the NGROUPS saga, a former pumpking prods
a mere committer to remove the last of the NGROUPS-sized arrays... Perl_magic_set() was using the last of these arrays to do the lvalue work on $). Instead of an array, a pointer is used and re-sized as needed. p4raw-id: //depot/perl@26492
Diffstat (limited to 'mg.c')
-rw-r--r--mg.c47
1 files changed, 28 insertions, 19 deletions
diff --git a/mg.c b/mg.c
index 5072a8f6f6..8172c4c7ee 100644
--- a/mg.c
+++ b/mg.c
@@ -40,14 +40,17 @@ tie.
#include "perl.h"
#if defined(HAS_GETGROUPS) || defined(HAS_SETGROUPS)
-# ifndef NGROUPS
-# define NGROUPS 32
-# endif
# ifdef I_GRP
# include <grp.h>
# endif
#endif
+#if defined(HAS_SETGROUPS)
+# ifndef NGROUPS
+# define NGROUPS 32
+# endif
+#endif
+
#ifdef __hpux
# include <sys/pstat.h>
#endif
@@ -2489,22 +2492,28 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
#ifdef HAS_SETGROUPS
{
const char *p = SvPV_const(sv, len);
- Groups_t gary[NGROUPS];
-
- while (isSPACE(*p))
- ++p;
- PL_egid = Atol(p);
- for (i = 0; i < NGROUPS; ++i) {
- while (*p && !isSPACE(*p))
- ++p;
- while (isSPACE(*p))
- ++p;
- if (!*p)
- break;
- gary[i] = Atol(p);
- }
- if (i)
- (void)setgroups(i, gary);
+ Groups_t *gary = NULL;
+
+ while (isSPACE(*p))
+ ++p;
+ PL_egid = Atol(p);
+ for (i = 0; i < NGROUPS; ++i) {
+ while (*p && !isSPACE(*p))
+ ++p;
+ while (isSPACE(*p))
+ ++p;
+ if (!*p)
+ break;
+ if(!gary)
+ Newx(gary, i + 1, Groups_t);
+ else
+ Renew(gary, i + 1, Groups_t);
+ gary[i] = Atol(p);
+ }
+ if (i)
+ (void)setgroups(i, gary);
+ if (gary)
+ Safefree(gary);
}
#else /* HAS_SETGROUPS */
PL_egid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);