Примеры ошибок, обнаруженных с помощью диагностики V3095


V3095. The object was used before it was verified against null. Check lines: N1, N2.


WPF samples by Microsoft

V3095 The 'htmlLiElement' object was used before it was verified against null. Check lines: 916, 936. HtmlToXamlConverter.cs 916


private static XmlElement AddOrphanListItems(....)
{
  Debug.Assert(htmlLiElement.LocalName.ToLower() == "li");
  ....
  XmlNode htmlChildNode = htmlLiElement;
  var htmlChildNodeName = htmlChildNode == null
      ? null
      : htmlChildNode.LocalName.ToLower();
  ....
}

Old NASA World Wind (C#)

V3095 The 'this.linePoints' object was used before it was verified against null. Check lines: 332, 346. PathLine.cs 332


public override void Render(DrawArgs drawArgs)
{
  ....
  if(this.linePoints.Length > 1)    // <=
  {
    ....
    if(this.linePoints != null)     // <=
    {
      ....
    }
  }
  ....
}

Also see V3022


FlashDevelop

V3095 The 'node' object was used before it was verified against null. Check lines: 364, 365. ProjectContextMenu.cs 364


private void AddFolderItems(MergableMenu menu, string path)
{
  ....
  DirectoryNode node = projectTree.SelectedNode
    as DirectoryNode;
  if (node.InsideClasspath == node)
    menu.Add(RemoveSourcePath, 2, true);
  else if (node != null && ....)
  {
    menu.Add(AddSourcePath, 2, false);
  }
  ....
}

Unity3D

V3095 The 'uv2.gameObject' object was used before it was verified against null. Check lines: 1719, 1731. UnityEngine.Networking NetworkServer.cs 1719


static public bool SpawnObjects()
{
  ....
  if (uv2.gameObject.hideFlags == HideFlags.NotEditable ||
      uv2.gameObject.hideFlags == HideFlags.HideAndDontSave)
    continue;
  ....
  if (uv2.gameObject == null)
    continue;
  ....
}

Similar errors can be found in some other places:

  • V3095 The 'm_HorizontalScrollbarRect' object was used before it was verified against null. Check lines: 214, 220. UnityEngine.UI ScrollRect.cs 214
  • V3095 The 'm_VerticalScrollbarRect' object was used before it was verified against null. Check lines: 215, 221. UnityEngine.UI ScrollRect.cs 215

MSBuild

V3095 The 'diskRoots' object was used before it was verified against null. Check lines: 2656, 2659. ToolLocationHelper.cs 2656


private static void ExtractSdkDiskRootsFromEnvironment
(List<string> diskRoots, string directoryRoots)
{
  if (!String.IsNullOrEmpty(directoryRoots))
  {
    ....
    diskRoots.AddRange(splitRoots);  // <=
  }

  if (diskRoots != null)             // <=
  ....
}

Similar errors can be found in some other places:

  • V3095 The 'propertyValue' object was used before it was verified against null. Check lines: 2760, 2799. Expander.cs 2760
  • V3095 The 'publicKeyToken' object was used before it was verified against null. Check lines: 232, 236. GenerateBindingRedirects.cs 231
  • V3095 The 'searchLocation' object was used before it was verified against null. Check lines: 170, 178. Resolver.cs 170
  • And 7 additional diagnostic messages.

GitExtensions

V3095 The 'data' object was used before it was verified against null. Check lines: 319, 376. GitCommands RevisionGraph.cs 319


void DataReceived(string data)
{
  if (data.StartsWith(CommitBegin)) // <=
  {
      ....
  }

  if (!string.IsNullOrEmpty(data))
  {
      ....
  }
}

Similar errors can be found in some other places:

  • V3095 The 'line' object was used before it was verified against null. Check lines: 1979, 1981. GitCommands GitModule.cs 1979
  • V3095 The 'head' object was used before it was verified against null. Check lines: 2414, 2422. GitCommands GitModule.cs 2414

PowerShell

V3095 The 'inputParameters' object was used before it was verified against null. Check lines: 430, 436. System.Management.Automation FormatViewGenerator_Complex.cs 430


internal ComplexViewEntry
  GenerateView(....,
               FormattingCommandLineParameters inputParameters)
{
  _complexSpecificParameters =
    (ComplexSpecificParameters)inputParameters.shapeParameters;

  int maxDepth = _complexSpecificParameters.maxDepth;
  ....
  if (inputParameters != null)
    mshParameterList = inputParameters.mshParameterList;
  ....
}

PowerShell

V3095 The 'other.Parameters' object was used before it was verified against null. Check lines: 189, 192. System.Management.Automation CommandMetadata.cs 189


public CommandMetadata(CommandMetadata other)
{
  ....
  _parameters = new Dictionary<string, ParameterMetadata>(
    other.Parameters.Count, StringComparer.OrdinalIgnoreCase);

  // deep copy
  if (other.Parameters != null)
  ....
}

Orchard CMS

V3095 The 'Delegate' object was used before it was verified against null. Check lines: 37, 40. SerializableDelegate.cs 37


void ISerializable.GetObjectData(
  SerializationInfo info,
  StreamingContext context)
{
  info.AddValue("delegateType", Delegate.GetType());
  ....
  if (.... && Delegate != null)
  {
    ....
  }
}

Similar errors can be found in some other places:

  • V3095 The 'widget' object was used before it was verified against null. Check lines: 81, 93. TagsWidgetCommands.cs 81

Umbraco

V3095 The 'dataset' object was used before it was verified against null. Check lines: 48, 49. ImageCropperBaseExtensions.cs 48


internal static ImageCropData GetCrop(....)
{
  var imageCropDatas = dataset.ToArray();
  if (dataset == null || imageCropDatas.Any() == false)
    return null;
  ....
}

Similar errors can be found in some other places:

  • V3095 The 'display.PropertyEditor' object was used before it was verified against null. Check lines: 30, 43. ContentPropertyDisplayConverter.cs 30
  • V3095 The 'typedSource' object was used before it was verified against null. Check lines: 164, 198. DynamicQueryable.cs 164
  • V3095 The 'attempt.Result' object was used before it was verified against null. Check lines: 90, 113. DynamicPublishedContent.cs 90
  • And 8 additional diagnostic messages.

SharpDevelop

V3095 The 'position' object was used before it was verified against null. Check lines: 204, 206. Task.cs 204


public void JumpToPosition()
{
  if (hasLocation && !position.IsDeleted)
    ....
  else if (position != null)
    ....
}

Media Portal 2

V3095 The 'result' object was used before it was verified against null. Check lines: 1292, 1294. VideoMetadataExtractor.cs 1292


public bool TryExtractMetadata(....)
{
  using (Stream stream = fsra.OpenRead())
    result.MimeType = MimeTypeDetector.GetMimeType(
      stream, DEFAULT_MIMETYPE);

  if (result != null)                         // <=
  {
    ....
  }
}

Similar errors can be found in some other places:

  • V3095 The '_type' object was used before it was verified against null. Check lines: 104, 106. AbstractProperty.cs 104
  • V3095 The 'seasonDetail' object was used before it was verified against null. Check lines: 360, 361. OmDbWrapper.cs 360

PascalABC.NET

V3095 The 'VisualEnvironmentCompiler.RemoteCompiler' object was used before it was verified against null. Check lines: 52, 54. CompilerController CompilerControllerPlugin.cs 52


public CompilerController_VisualPascalABCPlugin(....)
{
  ....
  VisualEnvironmentCompiler.RemoteCompiler.InternalDebug.
    RunOnMono = CompilerInformation.cbRunMono.Checked;
  ....
  if (VisualEnvironmentCompiler.RemoteCompiler != null)
    ....
}

Similar errors can be found in some other places:

  • V3095 The 'cun' object was used before it was verified against null. Check lines: 400, 401. Compiler PCUReader.cs 400
  • V3095 The 'cnfn.ConnectedToType.element_type' object was used before it was verified against null. Check lines: 2918, 2930. Compiler PCUReader.cs 2918
  • V3095 The '_currentTreeNode' object was used before it was verified against null. Check lines: 590, 593. TreeConverter CapturedVariablesTreeBuilder.cs 590
  • And 7 additional diagnostic messages.

Unity C# reference source code

V3095 CWE-476 The 'element' object was used before it was verified against null. Check lines: 101, 107. StyleContext.cs 101


public override void
OnBeginElementTest(VisualElement element, ....)
{
  if (element.IsDirty(ChangeType.Styles))
  {
    ....
  }

  if (element != null && element.styleSheets != null)
  {
    ....
  }
  ....
}

Similar errors can be found in some other places:

  • V3095 CWE-476 The 'property' object was used before it was verified against null. Check lines: 5137, 5154. EditorGUI.cs 5137
  • V3095 CWE-476 The 'exposedPropertyTable' object was used before it was verified against null. Check lines: 152, 154. ExposedReferenceDrawer.cs 152
  • V3095 CWE-476 The 'rectObjs' object was used before it was verified against null. Check lines: 97, 99. RectSelection.cs 97
  • And 7 additional diagnostic messages.

Infer.NET

V3095 The 'quantiles' object was used before it was verified against null. Check lines: 91, 92. Runtime OuterQuantiles.cs 91


public static double GetQuantile(double probability,
                                 double[] quantiles)
{
  ....
  int n = quantiles.Length;
  if (quantiles == null)
    throw new ArgumentNullException(nameof(quantiles));
  if (n == 0)
    throw new ArgumentException("quantiles array is empty", nameof(quantiles));
  ....
}

AWS SDK for .NET

V3095 [CWE-476] The 'conditionValues' object was used before it was verified against null. Check lines: 228, 238. AWSSDK.Core.Net45 JsonPolicyWriter.cs 228


private static void writeConditions(....)
{
  ....
  foreach (....)
  {
    IList<string> conditionValues = keyEntry.Value;
    if (conditionValues.Count == 0) // <=
      continue;
    ....
    if (conditionValues != null && conditionValues.Count != 0)
    {
      ....
    }
    ....
  }
}

Similar errors can be found in some other places:

  • V3095 [CWE-476] The 'ts.Listeners' object was used before it was verified against null. Check lines: 140, 143. AWSSDK.Core.Net45 Logger.Diagnostic.cs 140
  • V3095 [CWE-476] The 'obj' object was used before it was verified against null. Check lines: 743, 745. AWSSDK.Core.Net45 JsonMapper.cs 743
  • V3095 [CWE-476] The 'multipartUploadMultipartUploadpartsList' object was used before it was verified against null. Check lines: 65, 67. AWSSDK.S3.Net45 CompleteMultipartUploadRequestMarshaller.cs 65

.NET Core Libraries (CoreFX)

V3095 The 'context' object was used before it was verified against null. Check lines: 340, 346. Principal.cs 340


abstract public class Principal : IDisposable
{
  ....
  public void Save(PrincipalContext context)
  {
    ....

    if (   context.ContextType == ContextType.Machine  // <=
        || _ctx.ContextType == ContextType.Machine)
    {
      throw new InvalidOperationException(
        SR.SaveToNotSupportedAgainstMachineStore);
    }

    if (context == null)                               // <=
    {
      Debug.Assert(this.unpersisted == true);
      throw new InvalidOperationException(SR.NullArguments);
    }
    ....
  }
  ....
}

.NET Core Libraries (CoreFX)

V3095 The 'propertyNames' object was used before it was verified against null. Check lines: 990, 1004. DirectoryEntry.cs 990


public class DirectoryEntry : Component
{
  ....
  public void RefreshCache(string[] propertyNames)
  {
    ....
    object[] names = new object[propertyNames.Length];         // <=
    for (int i = 0; i < propertyNames.Length; i++)
      names[i] = propertyNames[i];
    ....
    if (_propertyCollection != null && propertyNames != null)  // <=
      ....
    ....
  }
  ....
}

.NET Core Libraries (CoreFX)

V3095 The 'outputStream' object was used before it was verified against null. Check lines: 654, 672. Icon.Windows.cs 654


public sealed partial class Icon :
  MarshalByRefObject, ICloneable, IDisposable, ISerializable
{
  ....
  public void Save(Stream outputStream)
  {
    if (_iconData != null)
    {
      outputStream.Write(_iconData, 0, _iconData.Length); // <=
    }
    else
    {
      ....
      if (outputStream == null)                           // <=
        throw new ArgumentNullException("dataStream");
      ....
    }
  }
  ....
}

.NET Core Libraries (CoreFX)

V3095 The 'seq' object was used before it was verified against null. Check lines: 880, 884. XmlQueryRuntime.cs 880


public IList<XPathNavigator> DocOrderDistinct(IList<XPathNavigator> seq)
{
  if (seq.Count <= 1) // <=
    return seq;

  XmlQueryNodeSequence nodeSeq = (XmlQueryNodeSequence)seq; // <=
  if (nodeSeq == null) // <=
    nodeSeq = new XmlQueryNodeSequence(seq);

  return nodeSeq.DocOrderDistinct(_docOrderCmp);
}

.NET Core Libraries (CoreFX)

V3095 The 'other' object was used before it was verified against null. Check lines: 1095, 1096. XPathNodePointer.cs 1095


internal XmlNodeOrder ComparePosition(XPathNodePointer other)
{
  RealFoliate();
  other.RealFoliate();
  Debug.Assert(other != null);
  ....
}

.NET Core Libraries (CoreFX)

V3095 The 'buffer' object was used before it was verified against null. Check lines: 51, 53. HttpRequestStream.cs 51


public override IAsyncResult BeginRead(byte[] buffer, ....)
{
  if (NetEventSource.IsEnabled)
  {
    NetEventSource.Enter(this);
    NetEventSource.Info(this,
                        "buffer.Length:" + buffer.Length +  // <=
                        " size:" + size +
                        " offset:" + offset);
  }
  if (buffer == null) // <=
  {
    throw new ArgumentNullException(nameof(buffer));
  }
  ....
}

Similar errors can be found in some other places:

  • V3095 The 'buffer' object was used before it was verified against null. Check lines: 49, 51. HttpResponseStream.cs 49
  • V3095 The 'buffer' object was used before it was verified against null. Check lines: 74, 75. HttpResponseStream.cs 74

.NET Core Libraries (CoreFX)

V3095 The 'tx' object was used before it was verified against null. Check lines: 3282, 3285. TransactionState.cs 3282


internal override void EnterState(InternalTransaction tx)
{
  if (tx._outcomeSource._isoLevel == IsolationLevel.Snapshot) // <=
  {
    throw TransactionException.CreateInvalidOperationException(
            ....,
            tx == null ? Guid.Empty : tx.DistributedTxId);   // <=
  }
  ....
}

Roslyn Analyzers

V3095 The 'rule' object was used before it was verified against null. Check lines: 2180, 2181. CodeFixProvider.cs 2180


internal static string GetFirstRuleName(ClassDeclarationSyntax declaration)
{
  SyntaxList<MemberDeclarationSyntax> members = declaration.Members;
  FieldDeclarationSyntax rule = null;

  foreach (MemberDeclarationSyntax member in members)
  {
     rule = member as FieldDeclarationSyntax;
     var ruleType = rule.Declaration.Type as IdentifierNameSyntax;
     if (rule != null
         && ruleType != null
         && ruleType.Identifier.Text == "DiagnosticDescriptor")
       {break;}
     rule = null;
  }
  ....
}


Найденные ошибки

Проверено проектов
354
Собрано ошибок
13 290

А ты совершаешь ошибки в коде?

Проверь с помощью
PVS-Studio

Статический анализ
кода для C, C++, C#
и Java

goto PVS-Studio;