New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH] Include negative index of array in warnings about an unitialized value wen constant folding isn't done. #11630
Comments
From gerard@ggoossen.netThis is a bug report for perl from gerard@ggoossen.net, From 15850133545e13d0450e92c1f2ec0cbb0891c085 Mon Sep 17 00:00:00 2001 When constant folding isn't done OP_NEGATE isn't merged with sv.c | 27 +++++++++++++++++++++++---- Inline Patchdiff --git a/sv.c b/sv.c
index ea78558..f555e44 100644
--- a/sv.c
+++ b/sv.c
@@ -13909,6 +13909,9 @@ S_find_uninit_var(pTHX_ const OP *const obase, const SV *const uninit_sv,
case OP_AELEM:
case OP_HELEM:
+ {
+ bool negate = FALSE;
+
if (PL_op == obase)
/* $a[uninit_expr] or $h{uninit_expr} */
return find_uninit_var(cBINOPx(obase)->op_last, uninit_sv, match);
@@ -13934,28 +13937,43 @@ S_find_uninit_var(pTHX_ const OP *const obase, const SV *const uninit_sv,
if (!sv)
break;
+ if (kid && kid->op_type == OP_NEGATE) {
+ negate = TRUE;
+ kid = cUNOPx(kid)->op_first;
+ }
+
if (kid && kid->op_type == OP_CONST && SvOK(cSVOPx_sv(kid))) {
/* index is constant */
+ SV* kidsv;
+ if (negate) {
+ kidsv = sv_2mortal(newSVpvs("-"));
+ sv_catsv(kidsv, cSVOPx_sv(kid));
+ }
+ else
+ kidsv = cSVOPx_sv(kid);
if (match) {
if (SvMAGICAL(sv))
break;
if (obase->op_type == OP_HELEM) {
- HE* he = hv_fetch_ent(MUTABLE_HV(sv), cSVOPx_sv(kid), 0, 0);
+ HE* he = hv_fetch_ent(MUTABLE_HV(sv), kidsv, 0, 0);
if (!he || HeVAL(he) != uninit_sv)
break;
}
else {
- SV * const * const svp = av_fetch(MUTABLE_AV(sv), SvIV(cSVOPx_sv(kid)), FALSE);
+ SV * const * const svp = av_fetch(MUTABLE_AV(sv),
+ negate ? - SvIV(cSVOPx_sv(kid)) : SvIV(cSVOPx_sv(kid)),
+ FALSE);
if (!svp || *svp != uninit_sv)
break;
}
}
if (obase->op_type == OP_HELEM)
return varname(gv, '%', o->op_targ,
- cSVOPx_sv(kid), 0, FUV_SUBSCRIPT_HASH);
+ kidsv, 0, FUV_SUBSCRIPT_HASH);
else
return varname(gv, '@', o->op_targ, NULL,
- SvIV(cSVOPx_sv(kid)), FUV_SUBSCRIPT_ARRAY);
+ negate ? - SvIV(cSVOPx_sv(kid)) : SvIV(cSVOPx_sv(kid)),
+ FUV_SUBSCRIPT_ARRAY);
}
else {
/* index is an expression;
@@ -13981,6 +13999,7 @@ S_find_uninit_var(pTHX_ const OP *const obase, const SV *const uninit_sv,
o->op_targ, NULL, 0, FUV_SUBSCRIPT_WITHIN);
}
break;
+ }
case OP_AASSIGN:
/* only examine RHS */
--
Flags: Site configuration information for perl 5.15.2: Configured by gerard at Sun Sep 4 13:21:43 CEST 2011. Summary of my perl5 (revision 5 version 15 subversion 2) configuration: Locally applied patches: @INC for perl 5.15.2: Environment for perl 5.15.2: |
From @cpansproutOn Sun Sep 04 04:27:02 2011, ggoossen wrote:
Thank you. Applied as e6c60e7. |
The RT System itself - Status changed from 'new' to 'open' |
@cpansprout - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#98366 (status was 'resolved')
Searchable as RT98366$
The text was updated successfully, but these errors were encountered: