This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
op.c: Fix EBCDIC-only bug
authorKarl Williamson <khw@cpan.org>
Tue, 18 Oct 2016 02:16:21 +0000 (20:16 -0600)
committerKarl Williamson <khw@cpan.org>
Tue, 18 Oct 2016 02:29:25 +0000 (20:29 -0600)
We have no tests that this fails for, but on an EBCDIC machine, the
branches here are incorrect.  They are trying to determine if a UTF-8
representation will be larger than a non-UTF-8 representation for code
points < 256.  The proper test is if the code points are UTF-8
invariant.

op.c

diff --git a/op.c b/op.c
index 1866632..34c9a60 100644 (file)
--- a/op.c
+++ b/op.c
@@ -5426,7 +5426,7 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
                        tbl[i] = (short)i;
                }
                else {
-                   if (i < 128 && r[j] >= 128)
+                   if (UVCHR_IS_INVARIANT(i) && ! UVCHR_IS_INVARIANT(r[j]))
                        grows = 1;
                    tbl[i] = r[j++];
                }
@@ -5473,7 +5473,8 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
                --j;
            }
            if (tbl[t[i]] == -1) {
-               if (t[i] < 128 && r[j] >= 128)
+                if (     UVCHR_IS_INVARIANT(t[i])
+                    && ! UVCHR_IS_INVARIANT(r[j]))
                    grows = 1;
                tbl[t[i]] = r[j];
            }