diff options
author | Karl Williamson <khw@cpan.org> | 2014-06-17 09:39:51 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2014-06-17 09:54:50 -0600 |
commit | b3211734a7d280a8b7c6acaaba333f8f6a314675 (patch) | |
tree | 6757b4dd98bba1bb29c215588121d22914f175e3 /pp.c | |
parent | e21c1f156f378627d5dcc0a326f14b0a11d80fde (diff) | |
download | perl-b3211734a7d280a8b7c6acaaba333f8f6a314675.tar.gz |
PATCH: [perl #121816] Add warning for repetition x < 0
I consider this experimental, so that if code breaks as a result, we
will remove it.
I chose the numeric warnings category. But misc or a new subcategory of
numeric might be better choices.
There is also the issue if someone is calculating the repeat count in
floating point and gets something that would be 0 if there were infinite
precision, but ends up being a very small negative number. The current
implementation will warn on that, but probably shouldn't. I suspect that
this would be extremely rare in practice.
Diffstat (limited to 'pp.c')
-rw-r--r-- | pp.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -1656,23 +1656,25 @@ PP(pp_repeat) else count = uv; } else { - const IV iv = SvIV_nomg(sv); - if (iv < 0) - count = 0; - else - count = iv; + count = SvIV_nomg(sv); } } else if (SvNOKp(sv)) { const NV nv = SvNV_nomg(sv); if (nv < 0.0) - count = 0; + count = -1; /* An arbitrary negative integer */ else count = (IV)nv; } else count = SvIV_nomg(sv); + if (count < 0) { + count = 0; + Perl_ck_warner(aTHX_ packWARN(WARN_NUMERIC), + "Negative repeat count does nothing"); + } + if (GIMME == G_ARRAY && PL_op->op_private & OPpREPEAT_DOLIST) { dMARK; static const char* const oom_list_extend = "Out of memory during list extend"; |