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 nullable usage on authenticode (#13791) #13804

Merged
merged 2 commits into from Oct 30, 2020

Conversation

mkswd
Copy link
Contributor

@mkswd mkswd commented Oct 17, 2020

PR Summary

Changed nullable usage for better implementation.
Change in Authenticode.cs

PR Context

Change has done due to issue #13791

PR Checklist

@ghost ghost assigned rjmholt Oct 17, 2020
@iSazonov iSazonov added CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log Hacktoberfest-Accepted Accepted to participate in Hacktoberfest labels Oct 19, 2020
@ghost ghost added the Review - Needed The PR is being reviewed label Oct 29, 2020
@ghost
Copy link

ghost commented Oct 29, 2020

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@TravisEz13 TravisEz13 added the WG-Security security related areas such as JEA label Oct 30, 2020
@rjmholt rjmholt merged commit fbca914 into PowerShell:master Oct 30, 2020
@ghost ghost removed the Review - Needed The PR is being reviewed label Oct 30, 2020
@iSazonov
Copy link
Collaborator

@mkswd Thanks for your contribution!

@iSazonov iSazonov added this to the 7.2.0-preview.1 milestone Oct 31, 2020
@@ -292,7 +292,7 @@ internal static Signature GetSignature(string fileName, string fileContent)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods")]
private static Signature GetSignatureFromCatalog(string filename)
{
if (Signature.CatalogApiAvailable.HasValue && !Signature.CatalogApiAvailable.Value)
if (Signature.CatalogApiAvailable.HasValue && !Signature.CatalogApiAvailable.GetValueOrDefault())
Copy link
Member

Choose a reason for hiding this comment

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

@iSazonov Why changing to GetValueOrDefault()? HasValue is already checked and thus it's fine to access .Value, not?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@daxian-dbw It is a recommendation from .Net team dotnet/runtime#33792 I opened #13791 for Hacktoberfest exclusively. It is not critical for us (no hot paths) but I hoped it is good for first time contributions.

Copy link
Member

Choose a reason for hiding this comment

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

I think the comment dotnet/runtime#33792 (comment) in that issue has a point. .Value is semantically more correct given that HasValue is already checked. There is a duplicate check on the boolean hasvalue field, but I don't think that affects the perf in practice.

For places where we can use GetValueOrDefault to replace both .HasValue and .Value, it makes sense to make the change, like in #13805 and #13808. But if we need to keep the .HasValue check, then I think using .Value afterwards is better.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree in common. Only there is another side - using different patterns decreases readability. I would prefer to use one pattern even though it looks unusual, especially since there are only a few of them in our code base. There is another reason why I prefer this. Now we often look at a code in .Net Runtime for a better understanding of how an application works and we consider this code as the best practice and high quality. Switching to a different code with a different style immediately causes discomfort. I believe that following .Net in this sense is the right direction - many of those who learn PowerShell code will be grateful to us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log Hacktoberfest-Accepted Accepted to participate in Hacktoberfest WG-Security security related areas such as JEA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants