From 0b0bcdd19f7ff428e2f7548fe79d8710381f9920 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 13 Apr 2011 20:38:34 +0200 Subject: [PATCH] Fixed bug in variable naming that could cause two variables to be assigned the same name (and subsequently triggering a crash in DeclareVariables). --- ICSharpCode.Decompiler/Ast/NameVariables.cs | 4 ++++ ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/Ast/NameVariables.cs b/ICSharpCode.Decompiler/Ast/NameVariables.cs index 338f0bd20..22e32d8f0 100644 --- a/ICSharpCode.Decompiler/Ast/NameVariables.cs +++ b/ICSharpCode.Decompiler/Ast/NameVariables.cs @@ -177,6 +177,10 @@ namespace ICSharpCode.Decompiler.Ast proposedName = GetNameByType(variable.Type); } + // remove any numbers from the proposed name + int number; + proposedName = SplitName(proposedName, out number); + if (!typeNames.ContainsKey(proposedName)) { typeNames.Add(proposedName, 0); } diff --git a/ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs b/ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs index 314c929b1..38d36411e 100644 --- a/ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs +++ b/ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs @@ -57,10 +57,12 @@ namespace ICSharpCode.Decompiler.Ast.Transforms Variables = { new VariableInitializer(v.Name, v.ReplacedAssignment.Right.Detach()).CopyAnnotationsFrom(v.ReplacedAssignment) } }; ExpressionStatement es = v.ReplacedAssignment.Parent as ExpressionStatement; - if (es != null) + if (es != null) { + // Note: if this crashes with 'Cannot replace the root node', check whether two variables were assigned the same name es.ReplaceWith(varDecl.CopyAnnotationsFrom(es)); - else + } else { v.ReplacedAssignment.ReplaceWith(varDecl); + } } } variablesToDeclare = null;