about summary refs log tree commit diff stats
path: root/miasm2/expression/simplifications_common.py
diff options
context:
space:
mode:
authorajax <devnull@localhost>2014-07-30 15:47:55 +0200
committerajax <devnull@localhost>2014-07-30 15:47:55 +0200
commitc33451c9e1874a54498c3ad9fda560631c94bb8a (patch)
tree0e55f8aff39851afbf2f14a9f3b0450f056aa89d /miasm2/expression/simplifications_common.py
parente97492dbd0b93c58305c7d5c5b4ecc538e7f7274 (diff)
downloadmiasm-c33451c9e1874a54498c3ad9fda560631c94bb8a.tar.gz
miasm-c33451c9e1874a54498c3ad9fda560631c94bb8a.zip
Simplification: Fix 'A op 0' with op == '-' bug, add corresponding test case
Diffstat (limited to 'miasm2/expression/simplifications_common.py')
-rw-r--r--miasm2/expression/simplifications_common.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/miasm2/expression/simplifications_common.py b/miasm2/expression/simplifications_common.py
index 208870eb..58cabaf4 100644
--- a/miasm2/expression/simplifications_common.py
+++ b/miasm2/expression/simplifications_common.py
@@ -92,9 +92,14 @@ def simp_cst_propagation(e_s, e):
     if op == '-' and len(args) == 1 and isinstance(args[0], ExprInt):
         return ExprInt(-args[0].arg)
     # A op 0 =>A
-    if op in ['+', '-', '|', "^", "<<", ">>", "<<<", ">>>"] and len(args) > 1:
+    if op in ['+', '|', "^", "<<", ">>", "<<<", ">>>"] and len(args) > 1:
         if isinstance(args[-1], ExprInt) and args[-1].arg == 0:
             args.pop()
+    # A - 0 =>A
+    if op == '-' and len(args) > 1 and args[-1].arg == 0:
+        assert(len(args) == 2) # Op '-' with more than 2 args: SantityCheckError
+        return args[0]
+
     # A * 1 =>A
     if op == "*" and len(args) > 1:
         if isinstance(args[-1], ExprInt) and args[-1].arg == 1: