This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Neither gv_fetchpvn_flags() nor hv_fetch() need a NUL terminated
authorNicholas Clark <nick@ccl4.org>
Thu, 25 Jan 2007 22:39:08 +0000 (22:39 +0000)
committerNicholas Clark <nick@ccl4.org>
Thu, 25 Jan 2007 22:39:08 +0000 (22:39 +0000)
string, so don't bother allocating buffer space or adding a NUL.

p4raw-id: //depot/perl@29983

gv.c
toke.c

diff --git a/gv.c b/gv.c
index 9617b82..39d7a61 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -742,14 +742,13 @@ Perl_gv_stashpvn(pTHX_ const char *name, U32 namelen, I32 flags)
     HV *stash;
     GV *tmpgv;
 
     HV *stash;
     GV *tmpgv;
 
-    if (namelen + 3 < sizeof smallbuf)
+    if (namelen + 2 < sizeof smallbuf)
        tmpbuf = smallbuf;
     else
        tmpbuf = smallbuf;
     else
-       Newx(tmpbuf, namelen + 3, char);
+       Newx(tmpbuf, namelen + 2, char);
     Copy(name,tmpbuf,namelen,char);
     tmpbuf[namelen++] = ':';
     tmpbuf[namelen++] = ':';
     Copy(name,tmpbuf,namelen,char);
     tmpbuf[namelen++] = ':';
     tmpbuf[namelen++] = ':';
-    tmpbuf[namelen] = '\0';
     tmpgv = gv_fetchpvn_flags(tmpbuf, namelen, flags, SVt_PVHV);
     if (tmpbuf != smallbuf)
        Safefree(tmpbuf);
     tmpgv = gv_fetchpvn_flags(tmpbuf, namelen, flags, SVt_PVHV);
     if (tmpbuf != smallbuf)
        Safefree(tmpbuf);
@@ -835,14 +834,13 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
                char smallbuf[128];
                char *tmpbuf;
 
                char smallbuf[128];
                char *tmpbuf;
 
-               if (len + 3 < (I32)sizeof (smallbuf))
+               if (len + 2 < (I32)sizeof (smallbuf))
                    tmpbuf = smallbuf;
                else
                    tmpbuf = smallbuf;
                else
-                   Newx(tmpbuf, len+3, char);
+                   Newx(tmpbuf, len+2, char);
                Copy(name, tmpbuf, len, char);
                tmpbuf[len++] = ':';
                tmpbuf[len++] = ':';
                Copy(name, tmpbuf, len, char);
                tmpbuf[len++] = ':';
                tmpbuf[len++] = ':';
-               tmpbuf[len] = '\0';
                gvp = (GV**)hv_fetch(stash,tmpbuf,len,add);
                gv = gvp ? *gvp : NULL;
                if (gv && gv != (GV*)&PL_sv_undef) {
                gvp = (GV**)hv_fetch(stash,tmpbuf,len,add);
                gv = gvp ? *gvp : NULL;
                if (gv && gv != (GV*)&PL_sv_undef) {
diff --git a/toke.c b/toke.c
index 25c3f3e..d4930d9 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -794,19 +794,19 @@ S_incline(pTHX_ char *s)
            char *tmpbuf, *tmpbuf2;
            GV **gvp, *gv2;
            STRLEN tmplen2 = strlen(s);
            char *tmpbuf, *tmpbuf2;
            GV **gvp, *gv2;
            STRLEN tmplen2 = strlen(s);
-           if (tmplen + 3 < sizeof smallbuf)
+           if (tmplen + 2 < sizeof smallbuf)
                tmpbuf = smallbuf;
            else
                tmpbuf = smallbuf;
            else
-               Newx(tmpbuf, tmplen + 3, char);
-           if (tmplen2 + 3 < sizeof smallbuf2)
+               Newx(tmpbuf, tmplen + 2, char);
+           if (tmplen2 + 2 < sizeof smallbuf2)
                tmpbuf2 = smallbuf2;
            else
                tmpbuf2 = smallbuf2;
            else
-               Newx(tmpbuf2, tmplen2 + 3, char);
+               Newx(tmpbuf2, tmplen2 + 2, char);
            tmpbuf[0] = tmpbuf2[0] = '_';
            tmpbuf[1] = tmpbuf2[1] = '<';
            tmpbuf[0] = tmpbuf2[0] = '_';
            tmpbuf[1] = tmpbuf2[1] = '<';
-           memcpy(tmpbuf + 2, cf, ++tmplen);
-           memcpy(tmpbuf2 + 2, s, ++tmplen2);
-           ++tmplen; ++tmplen2;
+           memcpy(tmpbuf + 2, cf, tmplen);
+           memcpy(tmpbuf2 + 2, s, tmplen2);
+           tmplen += 2; tmplen2 += 2;
            gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
            if (gvp) {
                gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
            gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
            if (gvp) {
                gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);