Make Irix hints adapt when n32 libm.so is missing
[p5sagit/p5-mst-13.2.git] / mg.c
diff --git a/mg.c b/mg.c
index 54ca044..cab0e59 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 '*':
@@ -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;
@@ -769,10 +764,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
@@ -1536,7 +1529,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);