This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
S_gv_stashsvpvn_cached(): add asserts
authorDavid Mitchell <davem@iabyn.com>
Mon, 27 Feb 2017 11:44:12 +0000 (11:44 +0000)
committerDavid Mitchell <davem@iabyn.com>
Mon, 27 Feb 2017 11:44:12 +0000 (11:44 +0000)
RT #130344

PL_stashcache holds SvIOK() scalars whose integer values are hidden
pointers to HVs. Add asserts that this is indeed the case.

gv.c

diff --git a/gv.c b/gv.c
index 8c85614..d32a9c5 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -1496,7 +1496,14 @@ S_gv_stashsvpvn_cached(pTHX_ SV *namesv, const char *name, U32 namelen, I32 flag
         (flags & SVf_UTF8) ? HVhek_UTF8 : 0, 0, NULL, 0
     );
 
-    if (he) return INT2PTR(HV*,SvIVX(HeVAL(he)));
+    if (he) {
+        SV *sv = HeVAL(he);
+        HV *hv;
+        assert(SvIOK(sv));
+        hv = INT2PTR(HV*, SvIVX(sv));
+        assert(SvTYPE(hv) == SVt_PVHV);
+        return hv;
+    }
     else if (flags & GV_CACHE_ONLY) return NULL;
 
     if (namesv) {