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 Feb 10, 2025
1 parent d860cbc commit ca9b8c7
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 @@ -3696,8 +3696,11 @@ PP_wrapped(pp_substr,
repl = (char*)bytes_to_utf8_free_me(
(U8*)repl, &repl_len, &free_me);
}
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);
Safefree(free_me);
}
Expand Down

0 comments on commit ca9b8c7

Please sign in to comment.