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

Fix CodeQL issues #278

Merged
merged 1 commit into from
Feb 26, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/PublicApiGenerator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PublicApiGenerator.Tool", "
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{FDD9792D-8E91-41C6-B42A-9E69831F61DF}"
ProjectSection(SolutionItems) = preProject
..\.github\codecov.yml = ..\.github\codecov.yml
..\.github\dependabot.yml = ..\.github\dependabot.yml
..\.github\labeler.yml = ..\.github\labeler.yml
EndProjectSection
Expand Down
18 changes: 8 additions & 10 deletions src/PublicApiGenerator/ApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,14 @@ bool IsSpecialConstraint(GenericParameterConstraint constraint)
PopulateAttributesThatDontAppearInCustomAttributes(type, attributes);
}

static void PopulateAttributesThatDontAppearInCustomAttributes(ICustomAttributeProvider type,
private static void PopulateAttributesThatDontAppearInCustomAttributes(ICustomAttributeProvider type,
CodeAttributeDeclarationCollection attributes)
{
if (type is TypeDefinition typeDefinition)
if (type is TypeDefinition typeDefinition && typeDefinition.Attributes.HasFlag(Mono.Cecil.TypeAttributes.Serializable))
{
if (typeDefinition.Attributes.HasFlag(Mono.Cecil.TypeAttributes.Serializable))
{
var attribute = new CodeAttributeDeclaration("System.SerializableAttribute");
attribute.Name = AttributeNameBuilder.Get(attribute.Name);
attributes.Add(attribute);
}
var attribute = new CodeAttributeDeclaration("System.SerializableAttribute");
attribute.Name = AttributeNameBuilder.Get(attribute.Name);
attributes.Add(attribute);
}
}

Expand Down Expand Up @@ -565,8 +562,9 @@ private static CodeExpression CreateInitialiserExpression(CustomAttributeArgumen
{
// CodeDOM outputs a verbatim string. Any string with \n is treated as such, so normalize
// it to make it easier for comparisons
value = Regex.Replace(s, @"\n", "\\n");
Copy link
Member Author

Choose a reason for hiding this comment

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

From CodeQL: This assignment to is useless, since its value is never read.

so bugfix here

value = Regex.Replace(s, @"\r\n|\r\\n", "\\r\\n");
s = Regex.Replace(s, @"\n", "\\n");
s = Regex.Replace(s, @"\r\n|\r\\n", "\\r\\n");
value = s;
}

return new CodePrimitiveExpression(value);
Expand Down
7 changes: 3 additions & 4 deletions src/PublicApiGenerator/CodeTypeReferenceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ private static string GetTypeNameCore(TypeReference type, IEnumerator<bool?>? nu

if (type is ArrayType array)
{
if (nullable)
return CSharpTypeKeyword.Get(GetTypeName(array.ElementType, nullabilityMap, NullableMode.Default, disableNested)) + "[]";
else
return GetTypeName(array.ElementType, nullabilityMap, NullableMode.Default, disableNested) + "[]";
return nullable
? CSharpTypeKeyword.Get(GetTypeName(array.ElementType, nullabilityMap, NullableMode.Default, disableNested)) + "[]"
: GetTypeName(array.ElementType, nullabilityMap, NullableMode.Default, disableNested) + "[]";
}

if (type is PointerType pointer)
Expand Down