-
Notifications
You must be signed in to change notification settings - Fork 0
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. 14: Local scope variable shadows member #346
Conversation
…adows member Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Phileco <[email protected]>
@@ -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 parent, Type localType) |
Check notice
Code scanning / CodeQL
Local scope variable shadows member
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 11 days ago
To fix the problem, we should rename the local variable loc
in the Emit
method to avoid shadowing the member variable loc
. This will make the code clearer and reduce the risk of confusion or bugs. The best way to do this is to choose a descriptive name for the local variable that reflects its purpose within the method.
-
Copy modified line R121 -
Copy modified line R124
@@ -120,6 +120,6 @@ | ||
|
||
private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location loc, IEntity parent, Type localType) | ||
private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location location, IEntity parent, Type localType) | ||
{ | ||
trapFile.type_mention(this, localType.TypeRef, parent); | ||
trapFile.type_mention_location(this, Context.CreateLocation(loc)); | ||
trapFile.type_mention_location(this, Context.CreateLocation(location)); | ||
} |
@@ -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 parent, Type localType) |
Check notice
Code scanning / CodeQL
Local scope variable shadows member
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 11 days ago
To fix the problem, we need to rename the local variable parent
in the Emit
method to avoid shadowing the member variable parent
. This will make the code clearer and prevent any potential confusion or bugs related to variable shadowing. The best way to fix this is to choose a new name for the local variable that clearly indicates its purpose and does not conflict with any member variables.
In this case, we can rename the local variable parent
to localParent
in the Emit
method. This change will be made in the file csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs
on line 121 and any other lines within the Emit
method where the local variable is used.
-
Copy modified line R121 -
Copy modified line R123
@@ -120,5 +120,5 @@ | ||
|
||
private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location loc, IEntity parent, Type localType) | ||
private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location loc, IEntity localParent, Type localType) | ||
{ | ||
trapFile.type_mention(this, localType.TypeRef, parent); | ||
trapFile.type_mention(this, localType.TypeRef, localParent); | ||
trapFile.type_mention_location(this, Context.CreateLocation(loc)); |
Signed-off-by: Phileco <[email protected]>
Potential fix for https://github.com/krishnprakash/codeql/security/code-scanning/14
To fix the problem, we need to rename the local variable
type
in theEmit
method to avoid shadowing the member variabletype
. This will make the code clearer and reduce the risk of errors. The best way to do this is to choose a new name for the local variable that accurately describes its purpose and does not conflict with any existing member variables.In this case, we can rename the local variable
type
tolocalType
in theEmit
method. This change will be made in the filecsharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs
on line 121.Suggested fixes powered by Copilot Autofix. Review carefully before merging.