about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJB Cayrou <jb.cayrou@gmail.com>2016-06-26 17:00:44 +0200
committerAjax <commial@gmail.com>2016-06-29 10:42:39 +0200
commit0892884efe94d6feee19fcae5dde0f5aa2223303 (patch)
treeaa52cc8936df4fae1da20c539744a62e2a63d363
parente067f41e34e9d99408be3b5194205390f05a8b2c (diff)
downloadmiasm-0892884efe94d6feee19fcae5dde0f5aa2223303.tar.gz
miasm-0892884efe94d6feee19fcae5dde0f5aa2223303.zip
Fix ExprOp_inf_signed + unit tests #385
-rw-r--r--miasm2/expression/simplifications_cond.py8
-rw-r--r--test/expression/simplifications.py6
2 files changed, 10 insertions, 4 deletions
diff --git a/miasm2/expression/simplifications_cond.py b/miasm2/expression/simplifications_cond.py
index c6e455b6..a5acdba6 100644
--- a/miasm2/expression/simplifications_cond.py
+++ b/miasm2/expression/simplifications_cond.py
@@ -197,13 +197,13 @@ def __comp_signed(arg1, arg2):
     """Return ExprInt1(1) if arg1 <s arg2 else ExprInt1(0)
     @arg1, @arg2: ExprInt"""
 
-    val1 = arg1.arg
+    val1 = int(arg1.arg)
     if val1 >> (arg1.size - 1) == 1:
-        val1 = - (arg1.mask.arg ^ val1 + 1)
+        val1 = - ((int(arg1.mask.arg) ^ val1) + 1)
 
-    val2 = arg2.arg
+    val2 = int(arg2.arg)
     if val2 >> (arg2.size - 1) == 1:
-        val2 = - (arg2.mask.arg ^ val2 + 1)
+        val2 = - ((int(arg2.mask.arg) ^ val2) + 1)
 
     return m2_expr.ExprInt1(1) if (val1 < val2) else m2_expr.ExprInt1(0)
 
diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py
index acef0904..a4592e9d 100644
--- a/test/expression/simplifications.py
+++ b/test/expression/simplifications.py
@@ -349,6 +349,12 @@ to_test = [
     (ExprOp_equal(ExprInt32(12), ExprInt32(-12)), ExprInt1(0)),
     (ExprCond(a - b, ExprInt1(0), ExprInt1(1)), ExprOp_equal(a, b)),
     (ExprCond(a + b, ExprInt1(0), ExprInt1(1)), ExprOp_equal(a, -b)),
+    (ExprOp_inf_signed(ExprInt32(-2), ExprInt32(3)), ExprInt1(1)),
+    (ExprOp_inf_signed(ExprInt32(3), ExprInt32(-3)), ExprInt1(0)),
+    (ExprOp_inf_signed(ExprInt32(2), ExprInt32(3)), ExprInt1(1)),
+    (ExprOp_inf_signed(ExprInt32(-3), ExprInt32(-2)), ExprInt1(1)),
+    (ExprOp_inf_signed(ExprInt32(0), ExprInt32(2)), ExprInt1(1)),
+    (ExprOp_inf_signed(ExprInt32(-3), ExprInt32(0)), ExprInt1(1)),
 ]
 
 expr_simp_cond = ExpressionSimplifier()