Convert strcpy to memcpy where we already know the length.
Nicholas Clark [Tue, 28 Jun 2005 22:02:03 +0000 (22:02 +0000)]
p4raw-id: //depot/perl@25007

gv.c
sv.c
util.c

diff --git a/gv.c b/gv.c
index e96ab50..5fac589 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -92,7 +92,7 @@ Perl_gv_fetchfile(pTHX_ const char *name)
     /* This is where the debugger's %{"::_<$filename"} hash is created */
     tmpbuf[0] = '_';
     tmpbuf[1] = '<';
-    strcpy(tmpbuf + 2, name);
+    memcpy(tmpbuf + 2, name, tmplen - 1);
     gv = *(GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, TRUE);
     if (!isGV(gv)) {
        gv_init(gv, PL_defstash, tmpbuf, tmplen, FALSE);
diff --git a/sv.c b/sv.c
index c2d8572..96a1e88 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -3308,7 +3308,7 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags)
        s = SvGROW_mutable(sv, len + 1);
        SvCUR_set(sv, len);
        SvPOKp_on(sv);
-       return strcpy(s, t);
+       return memcpy(s, t, len + 1);
     }
 }
 
diff --git a/util.c b/util.c
index 8e37c0c..fb7108f 100644 (file)
--- a/util.c
+++ b/util.c
@@ -765,7 +765,7 @@ Perl_savepv(pTHX_ const char *pv)
        char *newaddr;
        const STRLEN pvlen = strlen(pv)+1;
        New(902,newaddr,pvlen,char);
-       return strcpy(newaddr,pv);
+       return memcpy(newaddr,pv,pvlen);
     }
 
 }
@@ -812,16 +812,18 @@ char *
 Perl_savesharedpv(pTHX_ const char *pv)
 {
     register char *newaddr;
+    STRLEN pvlen;
     if (!pv)
        return Nullch;
 
-    newaddr = (char*)PerlMemShared_malloc(strlen(pv)+1);
+    pvlen = strlen(pv)+1;
+    newaddr = (char*)PerlMemShared_malloc(pvlen);
     if (!newaddr) {
        PerlLIO_write(PerlIO_fileno(Perl_error_log),
                      PL_no_mem, strlen(PL_no_mem));
        my_exit(1);
     }
-    return strcpy(newaddr,pv);
+    return memcpy(newaddr,pv,pvlen);
 }
 
 /*
@@ -2840,6 +2842,7 @@ Perl_find_script(pTHX_ const char *scriptname, bool dosearch, const char **searc
                len = strlen(scriptname);
                if (len+MAX_EXT_LEN+1 >= sizeof(tmpbuf))
                    break;
+               /* FIXME? Convert to memcpy  */
                cur = strcpy(tmpbuf, scriptname);
            }
        } while (extidx >= 0 && ext[extidx]     /* try an extension? */
@@ -2894,15 +2897,17 @@ Perl_find_script(pTHX_ const char *scriptname, bool dosearch, const char **searc
                tmpbuf[len++] = ':';
 #else
            if (len
-#if defined(atarist) || defined(__MINT__) || defined(DOSISH)
+#  if defined(atarist) || defined(__MINT__) || defined(DOSISH)
                && tmpbuf[len - 1] != '/'
                && tmpbuf[len - 1] != '\\'
-#endif
+#  endif
               )
                tmpbuf[len++] = '/';
            if (len == 2 && tmpbuf[0] == '.')
                seen_dot = 1;
 #endif
+           /* FIXME? Convert to memcpy by storing previous strlen(scriptname)
+            */
            (void)strcpy(tmpbuf + len, scriptname);
 #endif  /* !VMS */