From 784b14b66bd0de5fb0d2ab7b54b6bbe5a10f23a4 Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 4 Feb 2020 19:56:02 +0000 Subject: [PATCH] Improve safety of ForLoopConditionTransformer Desetude noticed that there are some cases where this transformation is unsafe - for example: `i > i++`. Skipping the transform if _either_ side of the comparison has a side effect, rather than _both_ sides, makes it safe. --- .../openrs2/deob/ast/transform/ForLoopConditionTransformer.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ForLoopConditionTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ForLoopConditionTransformer.kt index 1cfb2f6275..1d014417c5 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ForLoopConditionTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/ForLoopConditionTransformer.kt @@ -16,7 +16,7 @@ class ForLoopConditionTransformer : Transformer() { } val expr = compare.asBinaryExpr() - if (expr.left.hasSideEffects() && expr.right.hasSideEffects()) { + if (expr.hasSideEffects()) { return@ifPresent }