In this, the last tale of the NGROUPS saga, a former pumpking prods
authorSteve Peters <steve@fisharerojo.org>
Mon, 26 Dec 2005 17:29:13 +0000 (17:29 +0000)
committerSteve Peters <steve@fisharerojo.org>
Mon, 26 Dec 2005 17:29:13 +0000 (17:29 +0000)
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

mg.c

diff --git a/mg.c b/mg.c
index 5072a8f..8172c4c 100644 (file)
--- 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);