Don't modify namelen in the first half of gv_stashpvn()
authorVincent Pit <perl@profvince.com>
Thu, 10 Sep 2009 16:20:06 +0000 (18:20 +0200)
committerVincent Pit <perl@profvince.com>
Thu, 10 Sep 2009 16:38:01 +0000 (18:38 +0200)
As it may be needed later when the lookup failed.

This fixes [perl #69066].

However, from now, "package ::" and "package foo::" respectively introduce
the "::" and "foo::" packages. Deciding if this is the correct thing to do
ought to be addressed separately.

gv.c

diff --git a/gv.c b/gv.c
index c97d99c..3df4e27 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -855,17 +855,18 @@ Perl_gv_stashpvn(pTHX_ const char *name, U32 namelen, I32 flags)
     char *tmpbuf;
     HV *stash;
     GV *tmpgv;
+    U32 tmplen = namelen + 2;
 
     PERL_ARGS_ASSERT_GV_STASHPVN;
 
-    if (namelen + 2 <= sizeof smallbuf)
+    if (tmplen <= sizeof smallbuf)
        tmpbuf = smallbuf;
     else
-       Newx(tmpbuf, namelen + 2, char);
-    Copy(name,tmpbuf,namelen,char);
-    tmpbuf[namelen++] = ':';
-    tmpbuf[namelen++] = ':';
-    tmpgv = gv_fetchpvn_flags(tmpbuf, namelen, flags, SVt_PVHV);
+       Newx(tmpbuf, tmplen, char);
+    Copy(name, tmpbuf, namelen, char);
+    tmpbuf[namelen]   = ':';
+    tmpbuf[namelen+1] = ':';
+    tmpgv = gv_fetchpvn_flags(tmpbuf, tmplen, flags, SVt_PVHV);
     if (tmpbuf != smallbuf)
        Safefree(tmpbuf);
     if (!tmpgv)