develooper Front page | perl.perl5.porters | Postings from January 2001

[PATCH perl@8327] strings with \x{..} in the middle are corrupted

From:
Roca, Ignasi
Date:
January 5, 2001 03:31
Subject:
[PATCH perl@8327] strings with \x{..} in the middle are corrupted
Message ID:
5930DC161690D211966700902715754703738F96@madt009a.siemens.es
Strings with \x{..} in the middle are corrupted, test 22 of op/bop.t fails.
This happens in the paragrah that recodes what is accumulated before first
\x{...}.
It translates backwards character by character was is accumulated to utf8 by
calling uv_to_utf8.
This function adds a null character at the end in the destination buffer
that overwrites previous translated character.

Following there is a patch to corret this bug:

===============================================================
--- toke.c.orig Fri Jan  5 00:59:48 2001
+++ toke.c      Fri Jan  5 12:17:02 2001
@@ -1414,6 +1414,8 @@
                        if (hicount) {
                            char *old_pvx = SvPVX(sv);
                            char *src, *dst;
+                           U8 tmpbuf[UTF8_MAXLEN+1];
+                           U8 *tmpend;
                            d = SvGROW(sv, SvCUR(sv) + hicount + 1) + (d -
old_pvx);
 
                            src = d - 1;
@@ -1422,9 +1424,9 @@
 
                            while (src < dst) {
                                if (*src & 0x80) {
-                                   dst--;
-                                   uv_to_utf8((U8*)dst, (U8)*src--);
-                                   dst--;
+                                   tmpend = uv_to_utf8(tmpbuf, (U8)*src--);
+                                   dst -= tmpend - tmpbuf;
+                                   strncpy(dst+1, (char *)tmpbuf, tmpend -
tmpbuf);
                                }
                                else {
                                    *dst-- = *src--;



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About