# New Ticket Created by  Ron Blaschke 
# Please include the string:  [perl #43381]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=43381 >


With Visual C++ it's possible to add run time range checks for casts, to
check if there are any bits lost.  The change to F<src/mmd.c> ensures
the data is truncated before the cast, which I guess was intended in the
first place.  In <src/unicode.h> the UTF-8 bit mask should only affect a
byte, so we truncate the extra bits spilling over from the left shift.

F<src/pmc.c> is changed to free the lock (MUTEX_DESTROY) before freeing
the memory where it lives.

Changed Files:
    src/mmd.c
    src/unicode.h
    src/pmc.c


Ron
Index: src/mmd.c
===================================================================
--- src/mmd.c   (revision 19310)
+++ src/mmd.c   (working copy)
@@ -1083,8 +1083,8 @@
 static INTVAL
 distance_cmp(Interp *interp /*NULLOK*/, INTVAL a, INTVAL b)
 {
-    short da = (short)a & 0xffff;
-    short db = (short)b & 0xffff;
+    short da = (short) (a & 0xffff);
+    short db = (short) (b & 0xffff);
     /* sort first by distance */
     if (da > db)
         return 1;
Index: src/unicode.h
===================================================================
--- src/unicode.h       (revision 19310)
+++ src/unicode.h       (working copy)
@@ -68,7 +68,7 @@
 #define UTF8_IS_CONTINUATION(c)         ((c) >= 0x80u && (c) <= 0xBFu)
 #define UTF8_IS_CONTINUED(c)            ((c) &  0x80u)
 
-#define UTF8_START_MARK(len) (len == 1 ? 0 : 0x7Eu << (7-len))
+#define UTF8_START_MARK(len) (len == 1 ? 0 : (0x7Eu << (7-len)) & 0xFF)
 #define UTF8_START_MASK(len) (len == 1 ? 0x7Fu : 0x1Fu >> (len-2))
 
 #define UTF8_CONTINUATION_MARK           0x80u
Index: src/pmc.c
===================================================================
--- src/pmc.c   (revision 19310)
+++ src/pmc.c   (working copy)
@@ -426,8 +426,11 @@
          */
         Small_Object_Pool * const ext_pool =
             interp->arena_base->pmc_ext_pool;
-        if (PMC_sync(_class))
+        if (PMC_sync(_class)) {
+            MUTEX_DESTROY(PMC_sync(_class)->pmc_lock);
             mem_internal_free(PMC_sync(_class));
+            PMC_sync(_class) = NULL;
+        }
         ext_pool->add_free_object(interp, ext_pool, _class->pmc_ext);
     }
     _class->pmc_ext = NULL;

Reply via email to