perl-unicode

[PATCH 5.005_52] ord() and unpack("U*",...) should not be negative

1998-10-20 06:01:54
This patch fixes the following problems:

$ /local/perl/5.005_52/bin/perl -Mutf8 -le 'print ord("\x{FFFFFFFF}")'
-1

$ /local/perl/5.005_52/bin/perl -Mutf8 -le 'print unpack("U*", 
"\x{FFFFFFFF}\x{8FFFFFFF}")'
-1-1879048193

Regards,
Gisle


Index: pp.c
===================================================================
RCS file: /usr/home/aas/CVSROOT/perl_52/pp.c,v
retrieving revision 1.1.1.1
diff -u -u -r1.1.1.1 pp.c
--- pp.c        1998/10/06 17:30:50     1.1.1.1
+++ pp.c        1998/10/20 12:14:22
@@ -2126,15 +2126,15 @@
 PP(pp_ord)
 {
     djSP; dTARGET;
-    I32 value;
+    UV value;
     U8 *tmps = (U8*)POPp;
     I32 retlen;
 
     if (IN_UTF8 && (*tmps & 0x80))
-       value = (I32) utf8_to_uv(tmps, &retlen);
+       value = utf8_to_uv(tmps, &retlen);
     else
-       value = (I32) (*tmps & 255);
-    XPUSHi(value);
+       value = (UV)(*tmps & 255);
+    XPUSHu(value);
     RETURN;
 }
 
@@ -3436,7 +3436,7 @@
                    auint = utf8_to_uv((U8*)s, &along);
                    s += along;
                    sv = NEWSV(37, 0);
-                   sv_setiv(sv, (IV)auint);
+                   sv_setuv(sv, (UV)auint);
                    PUSHs(sv_2mortal(sv));
                }
            }

<Prev in Thread] Current Thread [Next in Thread>
  • [PATCH 5.005_52] ord() and unpack("U*",...) should not be negative, Gisle Aas <=