-
Notifications
You must be signed in to change notification settings - Fork 559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
builtin::trim return value numifies incorrectly in a loop #22784
Labels
Comments
It's not just for():
I expect it's TARG not being properly reset, looking into it. |
tonycoz
added a commit
to tonycoz/perl5
that referenced
this issue
Nov 26, 2024
In the reported test case, trim() sets TARG (used for the return value), and that is then evaluated in numeric context, setting the IV slot and pIOK and possible IOK. These aren't reset on the second call to trim from the same entersub OP, and since TARG is re-used it still has the IV slot and pIOK/IOK set, and so uses the cached numeric value when evaluating TARG in numeric context again. Clear all but the string related flags. Fixes Perl#22784
tonycoz
added a commit
to tonycoz/perl5
that referenced
this issue
Nov 27, 2024
In the reported test case, trim() sets TARG (used for the return value), and that is then evaluated in numeric context, setting the IV slot and pIOK and possible IOK. These aren't reset on the second call to trim from the same entersub OP, and since TARG is re-used it still has the IV slot and pIOK/IOK set, and so uses the cached numeric value when evaluating TARG in numeric context again. Clear all but the string related flags. Fixes Perl#22784
tonycoz
added a commit
to tonycoz/perl5
that referenced
this issue
Dec 1, 2024
refactor a lot of custom "set SV to a string code" away to sv_setpvn(), this: - fixed the original problem reported for Perl#22784, where TARG wasn't being reset properly and contained a cached numeric version of the result from the previous call. - removed some never executed code, since builtin::trim is only XS and is not an OP with the TARGLEX optimization - fixes a possible problem if the result of the first call to trim() is COWed. This 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. See thr PR Perl#22788 for some discussion on how we got here. Fixes Perl#22784
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
When used in a foreach loop, builtin::trim returns the same PV in subsequent iterations which then numifies to the same IV as in the first loop even though the PV has changed.
Reported by damien on IRC
Steps to Reproduce
Expected behavior
outputting a PV of '4', IV of 4, PV of '5', and IV of 5
Perl configuration
The text was updated successfully, but these errors were encountered: