diff options
| author | ajax <devnull@localhost> | 2014-07-30 15:47:55 +0200 |
|---|---|---|
| committer | ajax <devnull@localhost> | 2014-07-30 15:47:55 +0200 |
| commit | c33451c9e1874a54498c3ad9fda560631c94bb8a (patch) | |
| tree | 0e55f8aff39851afbf2f14a9f3b0450f056aa89d | |
| parent | e97492dbd0b93c58305c7d5c5b4ecc538e7f7274 (diff) | |
| download | miasm-c33451c9e1874a54498c3ad9fda560631c94bb8a.tar.gz miasm-c33451c9e1874a54498c3ad9fda560631c94bb8a.zip | |
Simplification: Fix 'A op 0' with op == '-' bug, add corresponding test case
| -rw-r--r-- | miasm2/expression/simplifications_common.py | 7 | ||||
| -rw-r--r-- | test/expression/simplifications.py | 2 |
2 files changed, 8 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: diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index 6b437218..0f217c72 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -155,6 +155,8 @@ to_test = [(ExprInt32(1) - ExprInt32(1), ExprInt32(0)), (a & b & ExprInt_fromsize(a.size, -1), a & b), (a | b | ExprInt_fromsize(a.size, -1), ExprInt_fromsize(a.size, -1)), + (ExprOp('-', ExprInt8(1), ExprInt8(0)), + ExprInt8(1)), ] for e, e_check in to_test[:]: |