Skip to content
This repository has been archived by the owner on Jun 18, 2023. It is now read-only.

Fix StackOverflowError in InsertNecessaryConversionsTransform #13

Open
wants to merge 1 commit into
base: hg_master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import com.strobel.decompiler.semantics.ResolveResult;
import com.strobel.functions.Function;

import java.util.ArrayDeque;
import java.util.Deque;

import static com.strobel.core.CollectionUtilities.*;

public class InsertNecessaryConversionsTransform extends ContextTrackingVisitor<Void> {
Expand All @@ -48,6 +51,7 @@ public class InsertNecessaryConversionsTransform extends ContextTrackingVisitor<
}

private final JavaResolver _resolver;
private final Deque<AstNode> replacements = new ArrayDeque<>();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a linked list, don't think array deque offers a benefit here, and it uses more memory for smaller stacks (default size 16)


public InsertNecessaryConversionsTransform(final DecompilerContext context) {
super(context);
Expand Down Expand Up @@ -333,7 +337,23 @@ public AstNode apply(final AstNode input) {
}

if (replacement != null) {
if (!replacements.isEmpty()) {
AstNode lastReplacement = replacements.peek();

if (lastReplacement instanceof CastExpression && replacement instanceof CastExpression) {
CastExpression lastCast = (CastExpression) lastReplacement;
CastExpression thisCast = (CastExpression) replacement;

if (lastCast.getType().toTypeReference().equals(thisCast.getType().toTypeReference())) {
return true;
}
}
}

replacements.push(replacement);
recurse(replacement);
replacements.pop();

return true;
}

Expand Down