Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential fix for code scanning alert no. 13: Local scope variable shadows member #345

Merged
merged 2 commits into from
Mar 11, 2025
Merged
Changes from 1 commit
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
Next Next commit
Potential fix for code scanning alert no. 13: Local scope variable sh…
…adows member

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Phileco <132178579+krishnprakash@users.noreply.github.com>
krishnprakash and github-advanced-security[bot] authored Mar 11, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 33783be289ebc5ee454c74df1eb768e32351f2ea
Original file line number Diff line number Diff line change
@@ -118,9 +118,9 @@
}
}

private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location loc, IEntity parent, Type type)
private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location loc, IEntity localParent, Type type)

Check notice

Code scanning / CodeQL

Local scope variable shadows member

Local scope variable 'loc' shadows [TypeMention.loc](1).

Copilot Autofix AI 18 days ago

To fix the problem, we need to rename the local variable loc in the Emit method to avoid shadowing the member variable loc. This will make the code clearer and prevent any potential confusion or bugs related to variable shadowing.

  • In general terms, we should rename the local variable to something unique that does not conflict with any member variables.
  • Specifically, we will rename the local variable loc in the Emit method to location.
  • This change will be made in the file csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs on line 121.
  • No additional methods, imports, or definitions are needed to implement this change.
Suggested changeset 1
csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs
@@ -120,6 +120,6 @@
 
-        private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location loc, IEntity localParent, Type type)
+        private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location location, IEntity localParent, Type type)
         {
             trapFile.type_mention(this, type.TypeRef, localParent);
-            trapFile.type_mention_location(this, Context.CreateLocation(loc));
+            trapFile.type_mention_location(this, Context.CreateLocation(location));
         }
EOF
@@ -120,6 +120,6 @@

private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location loc, IEntity localParent, Type type)
private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location location, IEntity localParent, Type type)
{
trapFile.type_mention(this, type.TypeRef, localParent);
trapFile.type_mention_location(this, Context.CreateLocation(loc));
trapFile.type_mention_location(this, Context.CreateLocation(location));
}
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated

Check notice

Code scanning / CodeQL

Local scope variable shadows member

Local scope variable 'type' shadows [TypeMention.type](1).

Copilot Autofix AI 18 days ago

To fix the problem, we need to rename the local variable type in the Emit method to avoid shadowing the member variable type. This can be done by choosing a different name for the local variable that clearly distinguishes it from the member variable. We will update the method signature and all references to the local variable within the method.

Suggested changeset 1
csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs
@@ -120,5 +120,5 @@
 
-        private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location loc, IEntity localParent, Type type)
+        private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location loc, IEntity localParent, Type localType)
         {
-            trapFile.type_mention(this, type.TypeRef, localParent);
+            trapFile.type_mention(this, localType.TypeRef, localParent);
             trapFile.type_mention_location(this, Context.CreateLocation(loc));
EOF
@@ -120,5 +120,5 @@

private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location loc, IEntity localParent, Type type)
private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location loc, IEntity localParent, Type localType)
{
trapFile.type_mention(this, type.TypeRef, localParent);
trapFile.type_mention(this, localType.TypeRef, localParent);
trapFile.type_mention_location(this, Context.CreateLocation(loc));
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
{
trapFile.type_mention(this, type.TypeRef, parent);
trapFile.type_mention(this, type.TypeRef, localParent);
trapFile.type_mention_location(this, Context.CreateLocation(loc));
}


Unchanged files with check annotations Beta

var index = 0;
foreach (var element in TupleElements.Where(e => e is not null))
{
trapFile.tuple_element(this, index++, element);

Check warning on line 50 in csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/TupleType.cs

GitHub Actions / unit-tests (ubuntu-latest)

Possible null reference argument for parameter 'field' in 'void Tuples.tuple_element(TextWriter trapFile, TupleType type, int index, Field field)'.

Check warning on line 50 in csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/TupleType.cs

GitHub Actions / CodeQL-Build

Possible null reference argument for parameter 'field' in 'void Tuples.tuple_element(TextWriter trapFile, TupleType type, int index, Field field)'.

Check warning on line 50 in csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/TupleType.cs

GitHub Actions / CodeQL-Build

Possible null reference argument for parameter 'field' in 'void Tuples.tuple_element(TextWriter trapFile, TupleType type, int index, Field field)'.

Check warning on line 50 in csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/TupleType.cs

GitHub Actions / stubgentest

Possible null reference argument for parameter 'field' in 'void Tuples.tuple_element(TextWriter trapFile, TupleType type, int index, Field field)'.

Check warning on line 50 in csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/TupleType.cs

GitHub Actions / stubgentest

Possible null reference argument for parameter 'field' in 'void Tuples.tuple_element(TextWriter trapFile, TupleType type, int index, Field field)'.

Check warning on line 50 in csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/TupleType.cs

GitHub Actions / unit-tests (windows-2019)

Possible null reference argument for parameter 'field' in 'void Tuples.tuple_element(TextWriter trapFile, TupleType type, int index, Field field)'.
}
// Note: symbol.Locations seems to be very inconsistent