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. 10
      ILSpy.AddIn/Commands/OpenILSpyCommand.cs
  4. 7
      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. 5
      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
case TypeCode.UInt16: case TypeCode.UInt16:
return val >= UInt16.MinValue && val <= UInt16.MaxValue; return val >= UInt16.MinValue && val <= UInt16.MaxValue;
case TypeCode.UInt32: case TypeCode.UInt32:
return val >= 0;
case TypeCode.UInt64: case TypeCode.UInt64:
return val >= 0; return val >= 0;
} }

1
ICSharpCode.Decompiler/Util/ResXResourceWriter.cs

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

10
ILSpy.AddIn/Commands/OpenILSpyCommand.cs

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

7
ILSpy.BamlDecompiler/BamlResourceEntryNode.cs

@ -57,7 +57,7 @@ namespace ILSpy.BamlDecompiler
AvalonEditTextOutput output = new AvalonEditTextOutput(); AvalonEditTextOutput output = new AvalonEditTextOutput();
try try
{ {
if (LoadBaml(output, token)) LoadBaml(output, token);
highlighting = HighlightingManager.Instance.GetDefinitionByExtension(".xml"); highlighting = HighlightingManager.Instance.GetDefinitionByExtension(".xml");
} }
catch (Exception ex) catch (Exception ex)
@ -71,13 +71,12 @@ namespace ILSpy.BamlDecompiler
return true; 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(); using var data = OpenStream();
XDocument xamlDocument = LoadIntoDocument(asm.GetPEFileOrNull(), asm.GetAssemblyResolver(), data, cancellationToken); XDocument xamlDocument = LoadIntoDocument(asm.GetPEFileOrNull(), asm.GetAssemblyResolver(), data, cancellationToken);
output.Write(xamlDocument.ToString()); output.Write(xamlDocument.ToString());
return true;
} }
internal static XDocument LoadIntoDocument(PEFile module, IAssemblyResolver assemblyResolver, internal static XDocument LoadIntoDocument(PEFile module, IAssemblyResolver assemblyResolver,

2
ILSpy.BamlDecompiler/Xaml/XamlPathDeserializer.cs

@ -174,7 +174,7 @@ namespace ILSpy.BamlDecompiler.Xaml
var size = ReadPoint(reader); var size = ReadPoint(reader);
double angle = reader.ReadXamlDouble(); 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); size, angle, largeArc ? '1' : '0', sweepDirection ? '1' : '0', pt1);
break; break;
} }

4
ILSpy/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs

@ -17,12 +17,10 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Disassembler; using ICSharpCode.Decompiler.Disassembler;
using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
@ -134,7 +132,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
case HandleKind.MethodSpecification: case HandleKind.MethodSpecification:
case HandleKind.MemberReference: case HandleKind.MemberReference:
var m = (mainModule.ResolveEntity(member, genericContext) as IMember)?.MemberDefinition; 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; return true;
} }

6
ILSpy/AvalonEdit/TextMarkerService.cs

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

2
ILSpy/Images/Images.cs

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

3
ILSpy/MainWindow.xaml.cs

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

5
ILSpy/Metadata/FlagsFilterControl.xaml.cs

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

3
SharpTreeView/SharpTreeNodeCollection.cs

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

3
SharpTreeView/TreeFlattener.cs

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

Loading…
Cancel
Save