Checking the .NET Core Libraries Source Code by Static Analyzer

Joined
Aug 15, 2019
Messages
16
Programming Experience
Beginner
.NET Core libraries is one of the most popular C# projects on GitHub. It's hardly a surprise, since it's widely known and used. Owing to this, an attempt to reveal the dark corners of the source code is becoming more captivating. So this is what was done with the help of the PVS-Studio static analyzer.

Example of the detected error:

C#:
private SearchResultCollection FindAll(bool findMoreThanOne)
{
  searchResult = null;

  DirectoryEntry clonedRoot = null;
  if (_assertDefaultNamingContext == null)
  {
    clonedRoot = SearchRoot.CloneBrowsable();
  }
  else
  {
    clonedRoot = SearchRoot.CloneBrowsable();
  }
  ....
}


PVS-Studio warning: V3004 The 'then' statement is equivalent to the 'else' statement. DirectorySearcher.cs 629

Regardless of whether the _assertDefaultNamingContext == null condition is true or false, the same actions will be undertaken, as then and else branches of the if statement have the same bodies. Either there should be another action in a branch, or you can omit the if statement not to confuse developers and the analyzer.

You can learn more about other detected errors in this article
 
Last edited by a moderator:
Does it look like your if statement produces an alternative output in either conditions?
 
Read the link you just quoted and it should make a lot of sense to you.
 
Read the link you just quoted and it should make a lot of sense to you.
I think that you may have misunderstood the point of this thread. It was to provide information rather than ask a question.
 
Yes, it appears so. I didn't notice until you pointed it out.

Kinda silly allowing "tips" to be published amongst categories where people mostly ask support questions.
 
Kinda silly allowing "tips" to be published amongst categories where people mostly ask support questions.
They should be flagged as tips when posted with the appropriate prefix to make it obvious, which this one was not originally. I also should have fixed that when I approved it, so the fault is shared.
 
How is the fault shared? I didn't approve it without tags, and its worded like a support topic. Ahh no problem.

Maybe consider creating a category for tips and tutorials, and move all the tip topics to the new category. That way they are not mixed in with general support topics. It would make it obvious where tutorials and tips should be posted and thus separates the two in a more organised way.
 
Back
Top Bottom