[m-rev.] for review: signed character conversion bugs

Peter Wang novalazy at gmail.com
Wed Sep 15 13:12:09 AEST 2010


Branches: main, 10.04

Fix problems with characters being converted to integers without an
(MR_UnsignedChar) cast.

compiler/polymorphism.m:
        Characters must use `private_builtin.builtin_compare_character'
        instead of that for int, otherwise we may miss an (MR_UnsignedChar)
        cast.

runtime/mercury_builtin_types.c:
        Add missing (MR_UnsignedChar) casts to
        `mercury__builtin____Compare____character_0_0'.

diff --git a/compiler/polymorphism.m b/compiler/polymorphism.m
index 1e12424..81dc3ca 100644
--- a/compiler/polymorphism.m
+++ b/compiler/polymorphism.m
@@ -3058,11 +3058,12 @@ get_special_proc_det(Type, SpecialPredId, ModuleInfo, PredName,
 
 get_category_name(CtorCat) = MaybeName :-
     (
-        ( CtorCat = ctor_cat_builtin(cat_builtin_int)
-        ; CtorCat = ctor_cat_builtin(cat_builtin_char)
-        ),
+        CtorCat = ctor_cat_builtin(cat_builtin_int),
         MaybeName = yes("int")
     ;
+        CtorCat = ctor_cat_builtin(cat_builtin_char),
+        MaybeName = yes("character")
+    ;
         CtorCat = ctor_cat_builtin(cat_builtin_float),
         MaybeName = yes("float")
     ;
diff --git a/runtime/mercury_builtin_types.c b/runtime/mercury_builtin_types.c
index d88194b..f7a4489 100644
--- a/runtime/mercury_builtin_types.c
+++ b/runtime/mercury_builtin_types.c
@@ -289,8 +289,10 @@ void MR_CALL
 mercury__builtin____Compare____character_0_0(
     MR_Comparison_Result *result, MR_Char x, MR_Char y)
 {
-    *result = (x > y ? MR_COMPARE_GREATER :
-          x == y ? MR_COMPARE_EQUAL :
+    MR_Integer xi = (MR_UnsignedChar)x;
+    MR_Integer yi = (MR_UnsignedChar)y;
+    *result = (xi > yi ? MR_COMPARE_GREATER :
+          xi == yi ? MR_COMPARE_EQUAL :
           MR_COMPARE_LESS);
 }
 

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list