Browse Source

Fix #2294: Issues discovered by static analysis.

pull/2301/head
Daniel Grunwald 5 years ago
parent
commit
7ebfc5ded5
  1. 1
      ICSharpCode.Decompiler/CSharp/Resolver/CSharpConversions.cs
  2. 1
      ICSharpCode.Decompiler/Util/ResXResourceWriter.cs
  3. 16
      ILSpy.AddIn/Commands/OpenILSpyCommand.cs
  4. 9
      ILSpy.BamlDecompiler/BamlResourceEntryNode.cs
  5. 2
      ILSpy.BamlDecompiler/Xaml/XamlPathDeserializer.cs
  6. 4
      ILSpy/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs
  7. 6
      ILSpy/AvalonEdit/TextMarkerService.cs
  8. 2
      ILSpy/Images/Images.cs
  9. 3
      ILSpy/MainWindow.xaml.cs
  10. 7
      ILSpy/Metadata/FlagsFilterControl.xaml.cs
  11. 3
      SharpTreeView/SharpTreeNodeCollection.cs
  12. 3
      SharpTreeView/TreeFlattener.cs

1
ICSharpCode.Decompiler/CSharp/Resolver/CSharpConversions.cs

@ -826,7 +826,6 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -826,7 +826,6 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
case TypeCode.UInt16:
return val >= UInt16.MinValue && val <= UInt16.MaxValue;
case TypeCode.UInt32:
return val >= 0;
case TypeCode.UInt64:
return val >= 0;
}

1
ICSharpCode.Decompiler/Util/ResXResourceWriter.cs

@ -60,7 +60,6 @@ namespace ICSharpCode.Decompiler.Util @@ -60,7 +60,6 @@ namespace ICSharpCode.Decompiler.Util
public static readonly string ByteArraySerializedObjectMimeType = "application/x-microsoft.net.object.bytearray.base64";
public static readonly string DefaultSerializedObjectMimeType = BinSerializedObjectMimeType;
public static readonly string ResMimeType = "text/microsoft-resx";
public static readonly string ResourceSchema = schema;
public static readonly string SoapSerializedObjectMimeType = "application/x-microsoft.net.object.soap.base64";
public static readonly string Version = "2.0";
#endregion // Static Fields

16
ILSpy.AddIn/Commands/OpenILSpyCommand.cs

@ -1,11 +1,8 @@ @@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Shell;
@ -93,10 +90,15 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -93,10 +90,15 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
foreach (var projectReference in parentProject.ProjectReferences)
{
var roslynProject = owner.Workspace.CurrentSolution.GetProject(projectReference.ProjectId);
var project = FindProject(owner.DTE.Solution.Projects.OfType<EnvDTE.Project>(), roslynProject.FilePath);
if (roslynProject != null && project != null)
dict.Add(roslynProject.AssemblyName,
new DetectedReference(roslynProject.AssemblyName, Utils.GetProjectOutputAssembly(project, roslynProject), true));
if (roslynProject != null)
{
var project = FindProject(owner.DTE.Solution.Projects.OfType<EnvDTE.Project>(), roslynProject.FilePath);
if (project != null)
{
dict.Add(roslynProject.AssemblyName,
new DetectedReference(roslynProject.AssemblyName, Utils.GetProjectOutputAssembly(project, roslynProject), true));
}
}
}
return dict;
}

9
ILSpy.BamlDecompiler/BamlResourceEntryNode.cs

@ -57,8 +57,8 @@ namespace ILSpy.BamlDecompiler @@ -57,8 +57,8 @@ namespace ILSpy.BamlDecompiler
AvalonEditTextOutput output = new AvalonEditTextOutput();
try
{
if (LoadBaml(output, token))
highlighting = HighlightingManager.Instance.GetDefinitionByExtension(".xml");
LoadBaml(output, token);
highlighting = HighlightingManager.Instance.GetDefinitionByExtension(".xml");
}
catch (Exception ex)
{
@ -71,13 +71,12 @@ namespace ILSpy.BamlDecompiler @@ -71,13 +71,12 @@ namespace ILSpy.BamlDecompiler
return true;
}
bool LoadBaml(AvalonEditTextOutput output, CancellationToken cancellationToken)
void LoadBaml(AvalonEditTextOutput output, CancellationToken cancellationToken)
{
var asm = this.Ancestors().OfType<AssemblyTreeNode>().FirstOrDefault().LoadedAssembly;
var asm = this.Ancestors().OfType<AssemblyTreeNode>().First().LoadedAssembly;
using var data = OpenStream();
XDocument xamlDocument = LoadIntoDocument(asm.GetPEFileOrNull(), asm.GetAssemblyResolver(), data, cancellationToken);
output.Write(xamlDocument.ToString());
return true;
}
internal static XDocument LoadIntoDocument(PEFile module, IAssemblyResolver assemblyResolver,

2
ILSpy.BamlDecompiler/Xaml/XamlPathDeserializer.cs

@ -174,7 +174,7 @@ namespace ILSpy.BamlDecompiler.Xaml @@ -174,7 +174,7 @@ namespace ILSpy.BamlDecompiler.Xaml
var size = ReadPoint(reader);
double angle = reader.ReadXamlDouble();
sb.AppendFormat(CultureInfo.InvariantCulture, "A{0} {2:R} {2} {3} {4}",
sb.AppendFormat(CultureInfo.InvariantCulture, "A{0} {1:R} {2} {3} {4}",
size, angle, largeArc ? '1' : '0', sweepDirection ? '1' : '0', pt1);
break;
}

4
ILSpy/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs

@ -17,12 +17,10 @@ @@ -17,12 +17,10 @@
// DEALINGS IN THE SOFTWARE.
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Linq;
using System.Reflection.Metadata;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
@ -134,7 +132,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin @@ -134,7 +132,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
case HandleKind.MethodSpecification:
case HandleKind.MemberReference:
var m = (mainModule.ResolveEntity(member, genericContext) as IMember)?.MemberDefinition;
if (m.MetadataToken == analyzedMethod.MetadataToken && m.ParentModule.PEFile == analyzedMethod.ParentModule.PEFile)
if (m != null && m.MetadataToken == analyzedMethod.MetadataToken && m.ParentModule.PEFile == analyzedMethod.ParentModule.PEFile)
{
return true;
}

6
ILSpy/AvalonEdit/TextMarkerService.cs

@ -116,8 +116,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit @@ -116,8 +116,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit
internal void Redraw(ISegment segment)
{
textView.Redraw(segment, DispatcherPriority.Normal);
if (RedrawRequested != null)
RedrawRequested(this, EventArgs.Empty);
RedrawRequested?.Invoke(this, EventArgs.Empty);
}
public event EventHandler RedrawRequested;
@ -280,8 +279,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit @@ -280,8 +279,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit
internal void OnDeleted()
{
if (Deleted != null)
Deleted(this, EventArgs.Empty);
Deleted?.Invoke(this, EventArgs.Empty);
}
void Redraw()

2
ILSpy/Images/Images.cs

@ -251,7 +251,7 @@ namespace ICSharpCode.ILSpy @@ -251,7 +251,7 @@ namespace ICSharpCode.ILSpy
baseImage = Images.Literal;
break;
case MemberIcon.EnumValue:
baseImage = Images.Literal;
baseImage = Images.EnumValue;
break;
case MemberIcon.Property:
baseImage = Images.Property;

3
ILSpy/MainWindow.xaml.cs

@ -783,8 +783,7 @@ namespace ICSharpCode.ILSpy @@ -783,8 +783,7 @@ namespace ICSharpCode.ILSpy
nd => nd.AncestorsAndSelf().OfType<AssemblyTreeNode>().Any(
a => oldAssemblies.Contains(a.LoadedAssembly))));
}
if (CurrentAssemblyListChanged != null)
CurrentAssemblyListChanged(this, e);
CurrentAssemblyListChanged?.Invoke(this, e);
}
void LoadInitialAssemblies()

7
ILSpy/Metadata/FlagsFilterControl.xaml.cs

@ -1,7 +1,5 @@ @@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
@ -43,7 +41,10 @@ namespace ICSharpCode.ILSpy.Metadata @@ -43,7 +41,10 @@ namespace ICSharpCode.ILSpy.Metadata
base.OnApplyTemplate();
listBox = Template.FindName("ListBox", this) as ListBox;
listBox.ItemsSource = FlagGroup.GetFlags(FlagsType, neutralItem: "<All>");
if (listBox != null)
{
listBox.ItemsSource = FlagGroup.GetFlags(FlagsType, neutralItem: "<All>");
}
var filter = Filter;

3
SharpTreeView/SharpTreeNodeCollection.cs

@ -47,8 +47,7 @@ namespace ICSharpCode.TreeView @@ -47,8 +47,7 @@ namespace ICSharpCode.TreeView
try
{
parent.OnChildrenChanged(e);
if (CollectionChanged != null)
CollectionChanged(this, e);
CollectionChanged?.Invoke(this, e);
}
finally
{

3
SharpTreeView/TreeFlattener.cs

@ -47,8 +47,7 @@ namespace ICSharpCode.TreeView @@ -47,8 +47,7 @@ namespace ICSharpCode.TreeView
public void RaiseCollectionChanged(NotifyCollectionChangedEventArgs e)
{
if (CollectionChanged != null)
CollectionChanged(this, e);
CollectionChanged?.Invoke(this, e);
}
public void NodesInserted(int index, IEnumerable<SharpTreeNode> nodes)

Loading…
Cancel
Save