Skip to content

Commit

Permalink
builtin::trim: just use sv_setpvn()
Browse files Browse the repository at this point in the history
This includes all the fixes and makes things simpler.

It does slightly change the taint behaviour, rather than making TARG
tainted iff source is tainted, it changes to the behaviour of the rest
of perl, making TARG tainted if any tainted input is seen in the
current expression.
  • Loading branch information
tonycoz committed Nov 27, 2024
1 parent 77474d0 commit a801bbc
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,26 +272,14 @@ XS(XS_builtin_trim)
}
}

SV_CHECK_THINKFIRST(TARG);
SvUPGRADE(TARG, SVt_PV);
SvGROW(TARG, len + 1);

Copy(start, SvPVX(TARG), len, U8);
SvPVX(TARG)[len] = '\0';
SvPOK_only_UTF8(TARG);
SvCUR_set(TARG, len);
sv_setpvn(TARG, (const char *)start, len);

if (DO_UTF8(source))
SvUTF8_on(TARG);
else
SvUTF8_off(TARG);

if (SvTAINTED(source))
SvTAINT(TARG);

SvSETMAGIC(TARG);

SETs(TARG);
SETTARG;

XSRETURN(1);
}
Expand Down

0 comments on commit a801bbc

Please sign in to comment.