]> git.vpit.fr Git - perl/modules/indirect.git/commitdiff
Fix getting the name of a GV(SV) kid of RV2SV that caused 'print' to segfault
authorVincent Pit <vince@profvince.com>
Wed, 15 Oct 2008 15:50:57 +0000 (17:50 +0200)
committerVincent Pit <vince@profvince.com>
Wed, 15 Oct 2008 15:50:57 +0000 (17:50 +0200)
indirect.xs

index 1f1ab9a69b3c9642dc37da47da2a615e1a147af1..5ec4e03e786b56147f88792b0ce23041d7593c8b 100644 (file)
@@ -146,10 +146,26 @@ STATIC OP *(*indirect_old_ck_rv2sv)(pTHX_ OP *) = 0;
 STATIC OP *indirect_ck_rv2sv(pTHX_ OP *o) {
  if (indirect_hint()) {
   OP *op = cUNOPo->op_first;
-  SV *name = cSVOPx_sv(op);
-  if (SvPOK(name) && (SvTYPE(name) >= SVt_PV)) {
+  const char *name = NULL;
+  STRLEN len;
+  switch (op->op_type) {
+   case OP_GV:
+   case OP_GVSV: {
+    GV *gv = cGVOPx_gv(op);
+    name = GvNAME(gv);
+    len  = GvNAMELEN(gv);
+    break;
+   }
+   default: {
+    SV *sv = cSVOPx_sv(op);
+    if (SvPOK(sv) && (SvTYPE(sv) >= SVt_PV))
+     name = SvPV_const(sv, len);
+    break;
+   }
+  }
+  if (name) {
    SV *sv = sv_2mortal(newSVpvn("$", 1));
-   sv_catsv(sv, name);
+   sv_catpvn(sv, name, len);
    o = CALL_FPTR(indirect_old_ck_rv2sv)(aTHX_ o);
    indirect_map_store(o, indirect_find(sv, PL_parser->oldbufptr), sv);
    return o;