stringify looses integerness
[p5sagit/p5-mst-13.2.git] / mg.c
diff --git a/mg.c b/mg.c
index 54ca044..eb58886 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -531,27 +531,20 @@ MAGIC *mg;
        break;
     case '(':
        sv_setiv(sv, (IV)gid);
-       s = buf;
-       (void)sprintf(s,"%d",(int)gid);
+       sv_setpvf(sv, "%Vd", (IV)gid);
        goto add_groups;
     case ')':
        sv_setiv(sv, (IV)egid);
-       s = buf;
-       (void)sprintf(s,"%d",(int)egid);
+       sv_setpvf(sv, "%Vd", (IV)egid);
       add_groups:
-       while (*s) s++;
 #ifdef HAS_GETGROUPS
        {
            Groups_t gary[NGROUPS];
-
            i = getgroups(NGROUPS,gary);
-           while (--i >= 0) {
-               (void)sprintf(s," %d", (int)gary[i]);
-               while (*s) s++;
-           }
+           while (--i >= 0)
+               sv_catpvf(sv, " %Vd", (IV)gary[i]);
        }
 #endif
-       sv_setpv(sv,buf);
        SvIOK_on(sv);   /* what a wonderful hack! */
        break;
     case '*':
@@ -598,7 +591,7 @@ MAGIC* mg;
     }
 #endif
 
-#if !defined(OS2) && !defined(AMIGAOS) && !defined(_WIN32)
+#if !defined(OS2) && !defined(AMIGAOS) && !defined(WIN32)
                            /* And you'll never guess what the dog had */
                            /*   in its mouth... */
     if (tainting) {
@@ -634,9 +627,11 @@ MAGIC* mg;
 
            while (s < strend) {
                struct stat st;
-               s = cpytill(tokenbuf, s, strend, ':', &i);
+               s = delimcpy(tokenbuf, tokenbuf + sizeof tokenbuf,
+                            s, strend, ':', &i);
                s++;
-               if (*tokenbuf != '/'
+               if (i >= sizeof tokenbuf   /* too long -- assume the worst */
+                     || *tokenbuf != '/'
                      || (Stat(tokenbuf, &st) == 0 && (st.st_mode & 2)) ) {
                    MgTAINTEDDIR_on(mg);
                    return 0;
@@ -644,7 +639,7 @@ MAGIC* mg;
            }
        }
     }
-#endif /* neither OS2 nor AMIGAOS nor _WIN32 */
+#endif /* neither OS2 nor AMIGAOS nor WIN32 */
 
     return 0;
 }
@@ -659,6 +654,45 @@ MAGIC* mg;
 }
 
 int
+magic_clear_all_env(sv,mg)
+SV* sv;
+MAGIC* mg;
+{
+#if defined(VMS)
+    die("Can't make list assignment to %%ENV on this system");
+#else
+#ifdef WIN32
+    char *envv = GetEnvironmentStrings();
+    char *cur = envv;
+    STRLEN len;
+    while (*cur) {
+       char *end = strchr(cur,'=');
+       if (end && end != cur) {
+           *end = '\0';
+           my_setenv(cur,Nullch);
+           *end = '=';
+           cur += strlen(end+1)+1;
+       }
+       else if ((len = strlen(cur)))
+           cur += len+1;
+    }
+    FreeEnvironmentStrings(envv);
+#else
+    I32 i;
+
+    if (environ == origenviron)
+       New(901, environ, 1, char*);
+    else
+       for (i = 0; environ[i]; i++)
+           Safefree(environ[i]);
+    environ[0] = Nullch;
+
+#endif
+#endif
+    return 0;
+}
+
+int
 magic_getsig(sv,mg)
 SV* sv;
 MAGIC* mg;
@@ -769,10 +803,8 @@ MAGIC* mg;
         * access to a known hint bit in a known OP, we can't
         * tell whether HINT_STRICT_REFS is in force or not.
         */
-       if (!strchr(s,':') && !strchr(s,'\'')) {
-           sprintf(tokenbuf, "main::%s",s);
-           sv_setpv(sv,tokenbuf);
-       }
+       if (!strchr(s,':') && !strchr(s,'\''))
+           sv_setpv(sv, form("main::%s", s));
        if (i)
            (void)rsignal(i, sighandler);
        else
@@ -1204,7 +1236,7 @@ SV* sv;
                croak(no_aelem, (I32)LvTARGOFF(sv));
        }
     }
-    SvREFCNT_inc(value);
+    (void)SvREFCNT_inc(value);
     SvREFCNT_dec(LvTARG(sv));
     LvTARG(sv) = value;
     LvTARGLEN(sv) = 0;
@@ -1536,7 +1568,8 @@ MAGIC* mg;
                    break;
                gary[i] = I_V(atof(p));
            }
-           (void)setgroups(i, gary);
+           if (i)
+               (void)setgroups(i, gary);
        }
 #else  /* HAS_SETGROUPS */
        egid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
@@ -1580,7 +1613,7 @@ MAGIC* mg;
            }
            /* can grab env area too? */
            if (origenviron && origenviron[0] == s + 1) {
-               my_setenv("NoNeSuCh", Nullch);
+               my_setenv("NoNe  SuCh", Nullch);
                                            /* force copy of environment */
                for (i = 0; origenviron[i]; i++)
                    if (origenviron[i] == s + 1)