Skip to content

Commit

Permalink
pp_substr: checking SvOK() is superfluous after SvPV_force_nomg()
Browse files Browse the repository at this point in the history
When replacing some characters in pp_substr, there should be no
need to check `SvOK(sv)`, since previous calls to
`SvPV_force_nomg(sv)` and (if needed) `sv_utf8_upgrade_nomg(sv);`
should always return a `sv` that is `SvOK`.
  • Loading branch information
richardleach committed Jan 10, 2025
1 parent f5f6b47 commit 55927f5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3438,8 +3438,11 @@ PP(pp_substr)
sv_utf8_upgrade(repl_sv_copy);
repl = SvPV_const(repl_sv_copy, repl_len);
}
if (!SvOK(sv))
SvPVCLEAR(sv);

/* The earlier SvPV_force_nomg(sv, curlen) should have ensured
* that sv is SvOK, even if it wasn't beforehand. */
assert(SvOK(sv));

sv_insert_flags(sv, byte_pos, byte_len, repl, repl_len, 0);
SvREFCNT_dec(repl_sv_copy);
}
Expand Down

0 comments on commit 55927f5

Please sign in to comment.