This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regexec.c: PATCH: [perl #114808]
authorKarl Williamson <public@khwilliamson.com>
Sat, 6 Oct 2012 16:06:57 +0000 (10:06 -0600)
committerKarl Williamson <public@khwilliamson.com>
Sat, 6 Oct 2012 19:50:14 +0000 (13:50 -0600)
commit7e0d5ad7c9cdb21b681e611b888acd41d34c4d05
tree2d99a40ca92780839184bb4783b7948fe81a659a
parentc72077c4fff72b66cdde1621c62fb4fd383ce093
regexec.c: PATCH: [perl #114808]

Commit c72077c4fff72b66cdde1621c62fb4fd383ce093 fixed a place where
to_byte_substr() fails, but the code continued as if it had succeeded.

There is yet another place where the return is not checked.  This commit
adds a check there.

However, it turns out that there is another underlying problem to
[perl #114808].  The function to_byte_substr() tries to downgrade the
substr fields in the regex program it is passed.  If it fails (because
something in it is expressible only in UTF-8), it permanently changes
that field to point to PL_sv_undef, thus losing the original
information.  This is fine as long as the program will be used once and
discarded.  However, there are places where the program is re-used, as
in the test case introduced by this commit, and the original value has
been lost.

To solve this, this commit also changes to_byte_substr() from returning
void to instead returning bool, indicating success or failure.   On
failure, the original substrs are left intact.

The calls to this function are correspondingly changed.  One of them had
a trace statement when the failure happens, I reworded it to be more
general and accurate (it was slightly misleading), and added the trace
to every such place, not just the one.

In addition, I found the use of the same ternary operation in 3 or 4
consecutive lines very hard to understand; and is inefficient unless
compiled under C optimization which avoids recalculating things.  So I
expanded the several nearly identical places in the code that do that so
that I could quickly see what is going on.
embed.fnc
proto.h
regexec.c
t/op/split_unicode.t