In perl.git, the branch smoke-me/iter-IV_MAX has been updated <http://perl5.git.perl.org/perl.git/commitdiff/5cf0f754cc801f996cbc32d9580d939e5798ac88?hp=1a13b0759af8c958576ca1da3d406f7abdf9d241>
- Log ----------------------------------------------------------------- commit 5cf0f754cc801f996cbc32d9580d939e5798ac88 Author: Nicholas Clark <[email protected]> Date: Mon Apr 16 07:51:49 2012 +0200 In pp_iter, handle end of range at IV_MAX without undefined behaviour. The previous code assumed that incrementing a signed integer value wraps. We're lucky that it has (so far), as it's undefined behaviour in C. So refactor to code which doesn't assume anything. ----------------------------------------------------------------------- Summary of changes: pp_hot.c | 16 +++++++--------- 1 files changed, 7 insertions(+), 9 deletions(-) diff --git a/pp_hot.c b/pp_hot.c index 89165d9..d93fe8f 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -1891,7 +1891,7 @@ PP(pp_iter) /* don't risk potential race */ if (SvREFCNT(*itersvp) == 1 && !SvMAGICAL(*itersvp)) { /* safe to reuse old SV */ - sv_setiv(*itersvp, cx->blk_loop.state_u.lazyiv.cur++); + sv_setiv(*itersvp, cx->blk_loop.state_u.lazyiv.cur); } else { @@ -1899,17 +1899,15 @@ PP(pp_iter) * completely new SV for closures/references to work as they * used to */ oldsv = *itersvp; - *itersvp = newSViv(cx->blk_loop.state_u.lazyiv.cur++); + *itersvp = newSViv(cx->blk_loop.state_u.lazyiv.cur); SvREFCNT_dec(oldsv); } - /* Handle end of range at IV_MAX */ - if ((cx->blk_loop.state_u.lazyiv.cur == IV_MIN) && - (cx->blk_loop.state_u.lazyiv.end == IV_MAX)) - { - cx->blk_loop.state_u.lazyiv.cur++; - cx->blk_loop.state_u.lazyiv.end++; - } + if (cx->blk_loop.state_u.lazyiv.cur == IV_MAX) { + /* Handle end of range at IV_MAX */ + cx->blk_loop.state_u.lazyiv.end = IV_MIN; + } else + ++cx->blk_loop.state_u.lazyiv.cur; RETPUSHYES; } -- Perl5 Master Repository
