diff options
author | Chip Salzenberg <chip@pobox.com> | 2011-10-10 18:59:42 -0700 |
---|---|---|
committer | Chip Salzenberg <chip@pobox.com> | 2011-10-10 19:00:05 -0700 |
commit | bbddc9e0e65fab109b17ff2bc97d20cd4a2d6929 (patch) | |
tree | 616c4a0c8e92d950deac9c3333055f2fb91767cb /pp.c | |
parent | c62c43fa0ce7bbd817460ad31190c51de83ab30f (diff) | |
download | perl-bbddc9e0e65fab109b17ff2bc97d20cd4a2d6929.tar.gz |
do not return useless value from void-context substr
Diffstat (limited to 'pp.c')
-rw-r--r-- | pp.c | 23 |
1 files changed, 14 insertions, 9 deletions
@@ -2971,6 +2971,7 @@ PP(pp_substr) IV len_iv = 0; int len_is_uv = 1; const I32 lvalue = PL_op->op_flags & OPf_MOD || LVRET; + const bool rvalue = (GIMME_V != G_VOID); const char *tmps; SV *repl_sv = NULL; const char *repl = NULL; @@ -3099,16 +3100,18 @@ PP(pp_substr) RETURN; } - SvTAINTED_off(TARG); /* decontaminate */ - SvUTF8_off(TARG); /* decontaminate */ - tmps += byte_pos; - sv_setpvn(TARG, tmps, byte_len); + + if (rvalue) { + SvTAINTED_off(TARG); /* decontaminate */ + SvUTF8_off(TARG); /* decontaminate */ + sv_setpvn(TARG, tmps, byte_len); #ifdef USE_LOCALE_COLLATE - sv_unmagic(TARG, PERL_MAGIC_collxfrm); + sv_unmagic(TARG, PERL_MAGIC_collxfrm); #endif - if (utf8_curlen) - SvUTF8_on(TARG); + if (utf8_curlen) + SvUTF8_on(TARG); + } if (repl) { SV* repl_sv_copy = NULL; @@ -3128,8 +3131,10 @@ PP(pp_substr) } } SPAGAIN; - SvSETMAGIC(TARG); - PUSHs(TARG); + if (rvalue) { + SvSETMAGIC(TARG); + PUSHs(TARG); + } RETURN; bound_fail: |