Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion csharp/autobuilder/Semmle.Autobuild/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Project(Autobuilder builder, string path) : base(builder, path)
{
projFile = builder.Actions.LoadXml(FullPath);
}
catch (Exception e) when (e is XmlException || e is FileNotFoundException)
catch (Exception ex) when (ex is XmlException || ex is FileNotFoundException)
{
builder.Log(Severity.Info, $"Unable to read project file {path}.");
return;
Expand Down
2 changes: 1 addition & 1 deletion csharp/autobuilder/Semmle.Autobuild/Solution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Solution(Autobuilder builder, string path, bool allowProject) : base(buil
{
solution = SolutionFile.Parse(FullPath);
}
catch (Exception e) when (e is InvalidProjectFileException || e is FileNotFoundException)
catch (Exception ex) when (ex is InvalidProjectFileException || ex is FileNotFoundException)
{
// We allow specifying projects as solutions in lgtm.yml, so model
// that scenario as a solution with just that one project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static void ExtractCIL(Layout layout, string assemblyPath, ILogger logger
}
}
}
catch (Exception ex)
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
{
logger.Log(Severity.Error, string.Format("Exception extracting {0}: {1}", assemblyPath, ex));
}
Expand Down
3 changes: 3 additions & 0 deletions csharp/extractor/Semmle.Extraction.CIL/Entities/Method.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ public MemberReferenceMethod(GenericContext gc, MemberReferenceHandle handle) :

declType = parentMethod == null ? parent as Type : parentMethod.DeclaringType;

if (declType is null)
throw new InternalError("Parent context of method is not a type");

ShortId = MakeMethodId(declType, nameLabel);

var typeSourceDeclaration = declType.SourceDeclaration;
Expand Down
2 changes: 1 addition & 1 deletion csharp/extractor/Semmle.Extraction.CIL/Entities/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ class GenericMethodParameter : ITypeSignature
static readonly Id excl = Id.Create("M!");
public Id MakeId(GenericContext outerGc)
{
if (innerGc != outerGc && innerGc is Method method)
if (!ReferenceEquals(innerGc, outerGc) && innerGc is Method method)
return open + method.Label.Value + close + excl + index;
return excl + index;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void AnalyseProjectFiles(FileInfo[] projectFiles)
}
++succeededProjects;
}
catch (Exception ex)
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
{
++failedProjects;
progressMonitor.FailedProjectFile(proj.FullName, ex.Message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ void RestoreNugetPackage(string package, IProgressMonitor pm)
}
}
}
catch (Exception e)
when (e is System.ComponentModel.Win32Exception || e is FileNotFoundException)
catch (Exception ex)
when (ex is System.ComponentModel.Win32Exception || ex is FileNotFoundException)
{
pm.FailedNugetCommand(pi.FileName, pi.Arguments, e.Message);
pm.FailedNugetCommand(pi.FileName, pi.Arguments, ex.Message);
}
}

Expand Down
6 changes: 3 additions & 3 deletions csharp/extractor/Semmle.Extraction.CSharp/Analyser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void SetReferencePaths()
extractor.SetAssemblyFile(assemblyIdentity, refPath);
}
}
catch (Exception ex)
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
{
extractor.Message(new Message
{
Expand Down Expand Up @@ -272,7 +272,7 @@ void DoAnalyseAssembly(PortableExecutableReference r)
ReportProgress(assemblyPath, trapWriter.TrapFile, stopwatch.Elapsed, skipExtraction ? AnalysisAction.UpToDate : AnalysisAction.Extracted);
}
}
catch (Exception ex)
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
{
Logger.Log(Severity.Error, " Unhandled exception analyzing {0}: {1}", r.FilePath, ex);
}
Expand Down Expand Up @@ -354,7 +354,7 @@ void DoExtractTree(SyntaxTree tree)

ReportProgress(sourcePath, trapPath, stopwatch.Elapsed, excluded ? AnalysisAction.Excluded : upToDate ? AnalysisAction.UpToDate : AnalysisAction.Extracted);
}
catch (Exception ex)
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
{
extractor.Message(new Message { exception = ex, message = string.Format("Unhandled exception processing {0}: {1}", tree.FilePath, ex), severity = Severity.Error });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ public static void ExtractModifiers(Context cx, IEntity key, ISymbol symbol)
if (symbol.Kind == SymbolKind.NamedType)
{
INamedTypeSymbol nt = symbol as INamedTypeSymbol;
if (nt is null)
throw new InternalError(symbol, "Symbol kind is inconsistent with its type");

if (nt.TypeKind == TypeKind.Struct)
{
// Sadly, these properties are internal so cannot be accessed directly.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Syntax; // lgtm[cs/similar-file]
using Semmle.Extraction.Kinds;

namespace Semmle.Extraction.CSharp.Entities.Statements
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Syntax; // lgtm[cs/similar-file]
using Semmle.Extraction.Kinds;

namespace Semmle.Extraction.CSharp.Entities.Statements
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Syntax; // lgtm[cs/similar-file]
using Semmle.Extraction.Kinds;

namespace Semmle.Extraction.CSharp.Entities.Statements
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Syntax; // lgtm[cs/similar-file]
using Semmle.Extraction.Kinds;

namespace Semmle.Extraction.CSharp.Entities.Statements
Expand Down
8 changes: 4 additions & 4 deletions csharp/extractor/Semmle.Extraction.CSharp/Extractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ public static ExitCode Run(string[] args)

return analyser.TotalErrors == 0 ? ExitCode.Ok : ExitCode.Errors;
}
catch (Exception e)
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
{
logger.Log(Severity.Error, " Unhandled exception: {0}", e);
logger.Log(Severity.Error, " Unhandled exception: {0}", ex);
return ExitCode.Errors;
}
}
Expand Down Expand Up @@ -354,9 +354,9 @@ public static void ExtractStandalone(

pm.MissingSummary(analyser.MissingTypes.Count(), analyser.MissingNamespaces.Count());
}
catch (Exception e)
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
{
analyser.Logger.Log(Severity.Error, " Unhandled exception: {0}", e);
analyser.Logger.Log(Severity.Error, " Unhandled exception: {0}", ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Semmle.Extraction.Kinds
namespace Semmle.Extraction.Kinds // lgtm[cs/similar-file]
{
/// <summary>
/// This enum has been auto-generated from the C# DB scheme - do not edit.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Semmle.Extraction.Kinds
namespace Semmle.Extraction.Kinds // lgtm[cs/similar-file]
{
/// <summary>
/// This enum has been auto-generated from the C# DB scheme - do not edit.
Expand Down
4 changes: 2 additions & 2 deletions csharp/extractor/Semmle.Extraction.CSharp/Populators/Ast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public static void Extract(this Context cx, CSharpSyntaxNode node, IExpressionPa
{
node.Accept(new Ast(cx, parent, child));
}
catch (System.Exception e)
catch (System.Exception ex) // lgtm[cs/catch-of-all-exceptions]
{
cx.ModelError(node, "Exception processing syntax node of type {0}: {1}", node.Kind(), e);
cx.ModelError(node, "Exception processing syntax node of type {0}: {1}", node.Kind(), ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public static IEntity CreateEntity(this Context cx, ISymbol symbol)
{
return symbol.Accept(new Symbols(cx));
}
catch (Exception e)
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
{
cx.ModelError(symbol, "Exception processing symbol '{2}' of type '{0}': {1}", symbol.Kind, e, symbol);
cx.ModelError(symbol, "Exception processing symbol '{2}' of type '{0}': {1}", symbol.Kind, ex, symbol);
return null;
}
}
Expand Down
12 changes: 6 additions & 6 deletions csharp/extractor/Semmle.Extraction/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void CheckEntityHasUniqueLabel(IId id, ICachedEntity entity)
{
if (idLabelCache.TryGetValue(id, out var originalEntity))
{
Extractor.Message(new Message { message = "Label collision for " + id.ToString(), severity = Severity.Warning });
Extractor.Message(new Message { message = "Label collision for " + id, severity = Severity.Warning });
}
else
{
Expand Down Expand Up @@ -216,13 +216,13 @@ public void PopulateAll()
{
populateQueue.Dequeue()();
}
catch (InternalError e)
catch (InternalError ex)
{
Extractor.Message(e.ExtractionMessage);
Extractor.Message(ex.ExtractionMessage);
}
catch (Exception e)
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
{
Extractor.Message(new Message { severity = Severity.Error, exception = e, message = "Uncaught exception" });
Extractor.Message(new Message { severity = Severity.Error, exception = ex, message = "Uncaught exception" });
}
}
}
Expand Down Expand Up @@ -504,7 +504,7 @@ static public void Try(this Context context, SyntaxNode node, ISymbol symbol, Ac
{
a();
}
catch (Exception ex)
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
{
var internalError = ex as InternalError;
var message = internalError != null
Expand Down
2 changes: 1 addition & 1 deletion csharp/extractor/Semmle.Extraction/Symbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void WithDuplicationGuard(System.Action a, IEntity location)
public override bool Equals(object obj)
{
var other = obj as CachedEntity<Initializer>;
return obj != null && obj.GetType() == GetType() && Equals(other.symbol, symbol);
return other?.GetType() == GetType() && Equals(other.symbol, symbol);
}

public abstract TrapStackBehaviour TrapStackBehaviour { get; }
Expand Down
2 changes: 1 addition & 1 deletion csharp/extractor/Semmle.Extraction/TrapWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void Dispose()
FileUtils.TryDelete(tmpFile);
}
}
catch (Exception ex)
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps we should disable this query in the .lgtm.yml file instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think leave this, because it would be in principle a good idea to receive new alerts for cs/catch-of-all-exceptions if we introduce new ones.

{
Logger.Log(Severity.Error, "Failed to move the trap file from {0} to {1} because {2}", tmpFile, TrapFile, ex);
}
Expand Down
6 changes: 3 additions & 3 deletions csharp/extractor/Semmle.Util/CanonicalPathCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class GetFinalPathNameByHandleStrategy : PathStrategy
/// <returns>The canonical path.</returns>
public override string GetCanonicalPath(string path, IPathCache cache)
{
using (var hFile = Win32.CreateFile(
using (var hFile = Win32.CreateFile( // lgtm[cs/call-to-unmanaged-code]
path,
0,
Win32.FILE_SHARE_READ | Win32.FILE_SHARE_WRITE,
Expand All @@ -88,13 +88,13 @@ public override string GetCanonicalPath(string path, IPathCache cache)
else
{
StringBuilder outPath = new StringBuilder(Win32.MAX_PATH);
int length = Win32.GetFinalPathNameByHandle(hFile, outPath, outPath.Capacity, 0);
int length = Win32.GetFinalPathNameByHandle(hFile, outPath, outPath.Capacity, 0); // lgtm[cs/call-to-unmanaged-code]
if (length >= outPath.Capacity)
{
// Path length exceeded MAX_PATH.
// Possible if target has a long path.
outPath = new StringBuilder(length + 1);
length = Win32.GetFinalPathNameByHandle(hFile, outPath, outPath.Capacity, 0);
length = Win32.GetFinalPathNameByHandle(hFile, outPath, outPath.Capacity, 0); // lgtm[cs/call-to-unmanaged-code]
}

const int PREAMBLE = 4; // outPath always starts \\?\
Expand Down
4 changes: 2 additions & 2 deletions csharp/extractor/Semmle.Util/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public FileLogger(Verbosity verbosity, string outputFile)
FileShare.ReadWrite, 8192));
writer.AutoFlush = true;
}
catch (Exception e)
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
{
Console.Error.WriteLine("SEMMLE: Couldn't initialise C# extractor output: " + e.Message + "\n" + e.StackTrace);
Console.Error.WriteLine("SEMMLE: Couldn't initialise C# extractor output: " + ex.Message + "\n" + ex.StackTrace);
Console.Error.Flush();
throw;
}
Expand Down
4 changes: 2 additions & 2 deletions csharp/extractor/Semmle.Util/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ namespace Semmle.Util
public class Win32
{
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int GetFinalPathNameByHandle(
public static extern int GetFinalPathNameByHandle( // lgtm[cs/unmanaged-code]
SafeHandle handle,
[In, Out] StringBuilder path,
int bufLen,
int flags);

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern SafeFileHandle CreateFile(
public static extern SafeFileHandle CreateFile( // lgtm[cs/unmanaged-code]
string filename,
uint desiredAccess,
uint shareMode,
Expand Down