Examples of errors detected by the V3080 diagnostic.


V3080. Possible null dereference.


Accord.Net

V3080 Possible null dereference. Consider inspecting 'fmt'. Accord.Statistics MultivariateMixture'1.cs 697


public override string ToString(string format,
                                IFormatProvider formatProvider)
{
  ....
  var fmt = components[i] as IFormattable;
  if (fmt != null)
    sb.AppendFormat(fmt.ToString(format, formatProvider));
  else
    sb.AppendFormat(fmt.ToString());
  ....
}

Old NASA World Wind (C#)

V3080 Possible null dereference. Consider inspecting 'm_gpsIcon'. GpsTrackerPlugin.SourceSetup.cs 68


public GpsSetup(....)
{
  ....
  if (m_gpsIcon!=null)
  {
    ....
    labelTitle.Text = "Set options for " +
                      m_gpsIcon.m_RenderInfo.sDescription;
  }
  else
  if (m_gpsTrackLine != null)
  {
    ....
    labelTitle.Text = "Set options for " +
                      m_gpsIcon.m_RenderInfo.sDescription; // <=
  }
  ....
}

Unity3D

V3080 Possible null dereference. Consider inspecting 't.staticFieldBytes'. MemoryProfiller CrawledDataUnpacker.cs 20


public static CrawledMemorySnapshot Unpack(....)
{
  ....
  var result = new CrawledMemorySnapshot
  {
    ....
    staticFields = packedSnapshot.typeDescriptions
      .Where(t =>
        t.staticFieldBytes != null & // <=
        t.staticFieldBytes.Length > 0)
      .Select(t => UnpackStaticFields(t))
      .ToArray(),
    ....
  };
  ....
}

PowerShell

V3080 Possible null dereference. Consider inspecting 'ItemSelectionCondition'. System.Management.Automation displayDescriptionData_List.cs 352


internal bool SafeForExport()
{
  return DisplayEntry.SafeForExport() &&
         ItemSelectionCondition == null
      || ItemSelectionCondition.SafeForExport();
}

Similar errors can be found in some other places:

  • V3080 Possible null dereference. Consider inspecting 'EntrySelectedBy'. System.Management.Automation displayDescriptionData_Wide.cs 247

PowerShell

V3080 Possible null dereference. Consider inspecting 'providerName'. System.Management.Automation SessionStateProviderAPIs.cs 1004


internal Collection<ProviderInfo> GetProvider(
  PSSnapinQualifiedName providerName)
{
  ....
  if (providerName == null)
  {
    ProviderNotFoundException e =
      new ProviderNotFoundException(
          providerName.ToString(),
          SessionStateCategory.CmdletProvider,
          "ProviderNotFound",
          SessionStateStrings.ProviderNotFound);

    throw e;
  }
  ....
}

Similar errors can be found in some other places:

  • V3080 Possible null dereference. Consider inspecting 'job'. System.Management.Automation PowerShellETWTracer.cs 1088

Umbraco

V3080 Possible null dereference. Consider inspecting 'context.Request'. StateHelper.cs 369


public static bool HasCookies
{
  get
  {
    var context = HttpContext;
    return context != null && context.Request != null &
           context.Request.Cookies != null &&
           context.Response != null &&
           context.Response.Cookies != null;
  }
}

Media Portal 2

V3080 Possible null dereference. Consider inspecting 'BannerPath'. TvdbBannerWithThumb.cs 91


public bool LoadThumb(bool replaceOld)
{
  ....
  if (ThumbPath == null &&
     (BannerPath != null || BannerPath.Equals(""))) // <=
  {
    ThumbPath = String.Concat("_cache/", BannerPath);
  }
  ....
}

.NET Core Libraries (CoreFX)

V3080 Possible null dereference. Consider inspecting 'tabClasses'. PropertyTabAttribute.cs 225


private void InitializeArrays(string[] tabClassNames,
  Type[] tabClasses, PropertyTabScope[] tabScopes)
{
  if (tabClasses != null)
  {
    if (tabScopes != null &&
        tabClasses.Length != tabScopes.Length)
    {
      ....
    }
    _tabClasses = (Type[])tabClasses.Clone();
  }
  else if (tabClassNames != null)
  {
    if (tabScopes != null &&
        tabClasses.Length != tabScopes.Length) // <=
    {
      ....
    }
    _tabClassNames = (string[])tabClassNames.Clone();
    _tabClasses = null;
  }

  ....
}

Used 'tabClasses' instead of 'tabClassNames'.

Similar errors can be found in some other places:

  • V3080 Possible null dereference. Consider inspecting 'BaseSimpleType'. SimpleType.cs 368

PascalABC.NET

V3080 Possible null dereference. Consider inspecting 'tc'. CodeCompletion CodeCompletionPCUReader.cs 736


private TypeScope GetTemplateInstance()
{
  TypeScope tc = null;//GetTemplateClassReference();
  int params_count = br.ReadInt32();
  for (int i = 0; i < params_count; i++)
  {
    tc.AddGenericInstanciation(GetTypeReference());  // <=
  }
  return tc;
}

Similar errors can be found in some other places:

  • V3080 Possible null dereference. Consider inspecting 'bfc'. TreeConverter syntax_tree_visitor.cs 7334
  • V3080 Possible null dereference. Consider inspecting 'bfc'. TreeConverter syntax_tree_visitor.cs 7336
  • V3080 Possible null dereference. Consider inspecting 'bfc'. TreeConverter syntax_tree_visitor.cs 7338
  • And 5 additional diagnostic messages.


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++, and C#

goto PVS-Studio;
On our website we use a cookie to collect information of a technical nature.
If you do not agree, please leave the site. Learn More →
Do not show again