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


V3125. The object was used after it was verified against null. Check lines: N1, N2.


Umbraco

V3125 The 'ct' object was used after it was verified against null. Check lines: 171, 163. ContentTypeControllerBase.cs 171


protected TContentType PerformPostSave<....>(....)
{
  var ctId = Convert.ToInt32(....);
  ....
  if (ctId > 0 && ct == null)
    throw new HttpResponseException(HttpStatusCode.NotFound);
  ....
  if ((....) &&
      (ctId == 0 || ct.Alias != contentTypeSave.Alias))
  ....
}

Similar errors can be found in some other places:

  • V3125 The '_repo' object was used after it was verified against null. Check lines: 104, 78. Installer.aspx.cs 104
  • V3125 The 'docRequest.RoutingContext.UmbracoContext' object was used after it was verified against null. Check lines: 57, 39. ContentFinderByIdPath.cs 57
  • V3125 The 'User' object was used after it was verified against null. Check lines: 90, 80. config.cs 90
  • And 5 additional diagnostic messages.

SharpDevelop

V3125 The 'mainAssemblyList' object was used after it was verified against null. Check lines: 304, 291. ClassBrowserPad.cs 304


void UpdateActiveWorkspace()
{
  var mainAssemblyList = SD.ClassBrowser.MainAssemblyList;
  if ((mainAssemblyList != null) && (activeWorkspace != null)) {
    ....
  }
  ....
  mainAssemblyList.Assemblies.Clear();
  ....
}

Media Portal 2

V3125 The 'root' object was used after it was verified against null. Check lines: 103, 98. SettingsFileHandler.cs 103


protected XmlElement GetPropertyElement(....)
{
  XmlElement root = _document.DocumentElement;
  if (root == null)
    if (!createIfNotExists)
      return null;
    else
      CreateRootElement();

  XmlElement entryElement = root.SelectSingleNode(        // <=
    "Property[@Name=\"" + entryName + "\"]") as XmlElement;
  ....
}

Similar errors can be found in some other places:

  • V3125 The 'e.Error' object was used after it was verified against null. Check lines: 467, 465. TextureAssetCore.cs 467

PascalABC.NET

V3125 The 'resources' object was used after it was verified against null. Check lines: 215, 211. VisualPascalABCNET DesignerResourceService.cs 215


public System.Resources.IResourceReader
  GetResourceReader(System.Globalization.CultureInfo info)
{
  ....
  if (resources != null && resources.ContainsKey(info.Name)) {
    resourceStorage = resources[info.Name];
  } else {
    resourceStorage = new ResourceStorage();
    resources[info.Name] = resourceStorage;  // <=
  }
  ....
}

Similar errors can be found in some other places:

  • V3125 The 'this._grid' object was used after it was verified against null. Check lines: 751, 746. VisualPascalABCNET TreeGridNode.cs 751
  • V3125 The 'this._grid' object was used after it was verified against null. Check lines: 774, 770. VisualPascalABCNET TreeGridNode.cs 774
  • V3125 The 'node.Parent' object was used after it was verified against null. Check lines: 369, 350. VisualPascalABCNET TreeGridView.cs 369
  • And 7 additional diagnostic messages.

Unity C# reference source code

V3125 CWE-476 The 'camera' object was used after it was verified against null. Check lines: 184, 180. ARBackgroundRenderer.cs 184


protected void DisableARBackgroundRendering()
{
  ....
  if (camera != null)
    camera.clearFlags = m_CameraClearFlags;

  // Command buffer
  camera.RemoveCommandBuffer(CameraEvent.BeforeForwardOpaque,
                             m_CommandBuffer);
  camera.RemoveCommandBuffer(CameraEvent.BeforeGBuffer,
                             m_CommandBuffer);
}

Unity C# reference source code

V3125 CWE-476 The 'item' object was used after it was verified against null. Check lines: 88, 85. TreeViewForAudioMixerGroups.cs 88


protected override Texture GetIconForItem(TreeViewItem item)
{
  if (item != null && item.icon != null)
    return item.icon;

  if (item.id == kNoneItemID) // <=
    return k_AudioListenerIcon;

  return k_AudioGroupIcon;
}

Similar errors can be found in some other places:

  • V3125 CWE-476 The 'element' object was used after it was verified against null. Check lines: 132, 107. StyleContext.cs 132
  • V3125 CWE-476 The 'mi.DeclaringType' object was used after it was verified against null. Check lines: 68, 49. AttributeHelper.cs 68
  • V3125 CWE-476 The 'label' object was used after it was verified against null. Check lines: 5016, 4999. EditorGUI.cs 5016
  • And 7 additional diagnostic messages.

AWS SDK for .NET

V3125 [CWE-476] The 'state' object was used after it was verified against null. Check lines: 139, 127. AWSSDK.Core.Net45 RefreshingAWSCredentials.cs 139


private void UpdateToGeneratedCredentials(
  CredentialsRefreshState state)
{
  string errorMessage;
  if (ShouldUpdate)
  {
    ....
    if (state == null)
      errorMessage = "Unable to generate temporary credentials";
    else
      ....
    throw new AmazonClientException(errorMessage);
  }

  state.Expiration -= PreemptExpiryTime;  // <=
  ....
}

Similar errors can be found in some other places:

  • V3125 [CWE-476] The 'wrappedRequest.Content' object was used after it was verified against null. Check lines: 395, 383. AWSSDK.Core.Net45 HttpHandler.cs 395
  • V3125 [CWE-476] The 'datasetUpdates' object was used after it was verified against null. Check lines: 477, 437. AWSSDK.CognitoSync.Net45 Dataset.cs 477
  • V3125 [CWE-476] The 'cORSConfigurationCORSConfigurationcORSRulesListValue' object was used after it was verified against null. Check lines: 125, 111. AWSSDK.S3.Net45 PutCORSConfigurationRequestMarshaller.cs 125
  • And 2 additional diagnostic messages.

.NET Core Libraries (CoreFX)

V3125 The '_table' object was used after it was verified against null. Check lines: 437, 423. ConstraintCollection.cs 437


public void Clear()
{
  if (_table != null)
    ....

  if (_table.fInitInProgress && _delayLoadingConstraints != null)
    ....
  ....
}

.NET Core Libraries (CoreFX)

V3125 The 'genericParameterConstraints' object was used after it was verified against null. Check lines: 603, 589. GenericSpecializationPartCreationInfo.cs 603


public static bool CanSpecialize(....)
{
  ....
  object[] genericParameterConstraints = ....;
  GenericParameterAttributes[] genericParameterAttributes = ....;

  if ((genericParameterConstraints == null) &&
      (genericParameterAttributes == null))
  {
    return true;
  }

  if ((genericParameterConstraints != null) &&
      (genericParameterConstraints.Length != partArity))
  {
    return false;
  }

  if ((genericParameterAttributes != null) &&
      (genericParameterAttributes.Length != partArity))
  {
    return false;
  }

  for (int i = 0; i < partArity; i++)
  {
    if (!GenericServices.CanSpecialize(
        specialization[i],
        (genericParameterConstraints[i] as Type[]).
          CreateTypeSpecializations(specialization),
        genericParameterAttributes[i]))
    {
      return false;
    }
  }

  return true;
}

Similar errors can be found in some other places:

  • V3125 The 'genericParameterAttributes' object was used after it was verified against null. Check lines: 604, 594. GenericSpecializationPartCreationInfo.cs 604

.NET Core Libraries (CoreFX)

V3125 The 'entry' object was used after it was verified against null. Check lines: 270, 227. FtpControlStream.cs 270


protected override PipelineInstruction PipelineCallback(
  PipelineEntry entry, ResponseDescription response, ....)
{
  if (NetEventSource.IsEnabled)
    NetEventSource.Info(this,
      $"Command:{entry?.Command} Description:{response?.StatusDescription}");
  ....
  if (entry.Command == "OPTS utf8 on\r\n")
    ....
  ....
}

.NET Core Libraries (CoreFX)

V3125 The 'ours' object was used after it was verified against null. Check lines: 1212, 1204. ImmutableArray_1.cs 1212


bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
{
  var self = this;
  Array otherArray = other as Array;
  if (otherArray == null)
  {
    var theirs = other as IImmutableArray;
    if (theirs != null)
    {
      otherArray = theirs.Array;

      if (self.array == null && otherArray == null) // <=
      {
        return true;
      }
      else if (self.array == null) // <=
      {
        return false;
      }
    }
  }

  IStructuralEquatable ours = self.array; // <=
  return ours.Equals(otherArray, comparer); // <=
}

Similar errors can be found in some other places:

  • V3125 The 'ours' object was used after it was verified against null. Check lines: 1265, 1251. ImmutableArray_1.cs 1265

.NET Core Libraries (CoreFX)

V3125 The 'n' object was used after it was verified against null. Check lines: 115, 111. CorrelationManager.cs 115


public override object Pop()
{
  StackNode n = _stack.Value;
  if (n == null) // <=
  {
    base.Pop();
  }
  _stack.Value = n.Prev; // <=
  return n.Value;
}

Roslyn Analyzers

V3125 The 'valueClauseName' object was used after it was verified against null. Check lines: 2320, 2318. DiagnosticAnalyzer.cs 2320


private SuppDiagReturnSymbolInfo SuppDiagReturnSymbol(....)
{
  ....
  var valueClauseName = valueClauseMemberAccess.Name as IdentifierNameSyntax;
  if (valueClauseName == null
      || valueClauseName.Identifier.Text != "Create")
     {
     ReportDiagnostic(context,
       SuppDiagReturnValueRule,
       valueClauseName.GetLocation(),                  // <=
       propertyDeclaration.Identifier.Text);
     return result;
     }
  ....
}

Roslyn Analyzers

V3125 The 'ifStatement' object was used after it was verified against null. Check lines: 788, 773. CodeFixProvider.cs 788


private async Task<Document> TriviaCountIncorrectAsync(
  MethodDeclarationSyntax declaration)
{
  SyntaxGenerator generator = SyntaxGenerator.GetGenerator(document);
  ....
  var ifStatement = declaration.Body.Statements[2] as IfStatementSyntax;
  if (ifStatement != null)
  {
    ....
  }
  ....
  var oldBlock = ifStatement.Statement as BlockSyntax;
  ....
}

Azure PowerShell

V3125 The 'startTime' object was used after it was verified against null. Check lines: 1752, 1738. AutomationPSClientDSC.cs 1752


private string GetNodeReportListFilterString(
  ....,
  DateTimeOffset? startTime,
  ....,
  DateTimeOffset? lastModifiedTime)
{
  ....
  if (startTime.HasValue)
  {
    odataFilter.Add("properties/startTime ge " +
      this.FormatDateTime(startTime.Value));      // <=
  }
  ....
  if (lastModifiedTime.HasValue)
  {
    odataFilter.Add("properties/lastModifiedTime ge " +
      this.FormatDateTime(startTime.Value));      // <=
  }
  ....
}

Similar errors can be found in some other places:

  • V3125 The 'firstPage' object was used after it was verified against null. Check lines: 113, 108. IntegrationAccountAgreementOperations.cs 113

Telerik UI for UWP

V3125 The 'CurrentAttachedMenu' object was used after it was verified against null. Check lines: 98, 96. PopupService.cs 98


private static void Overlay_PointerPressed(....)
{
  if (CurrentAttachedMenu == null ||
      !CurrentAttachedMenu.hitTestService
                          .HitTest(e.GetCurrentPoint(CurrentAttachedMenu)
                                    .Position)
                          .Any())
  {
    CurrentAttachedMenu.IsOpen = false;
    HideOverlay();
  }
}

Azure SDK for .NET

V3125 The 'omPropertyData' object was used after it was verified against null. Check lines: 156, 148. CodeGenerationUtilities.cs 156


private static string GetProtocolCollectionToObjectModelCollectionString(
  ...., PropertyData omPropertyData, ....)
{
  if (IsMappedEnumPair(omPropertyData?.GenericTypeParameter, ....))
  {
    ....
  }

  if (IsTypeComplex(omPropertyData.GenericTypeParameter))
  ....
}

Azure SDK for .NET

V3125 The 'session' object was used after it was verified against null. Check lines: 69, 68. AmqpLinkCreator.cs 69


public async Task<Tuple<AmqpObject, DateTime>> CreateAndOpenAmqpLinkAsync()
{
  ....
  AmqpSession session = null;
  try
  {
    // Create Session
    ....
    session = amqpConnection.CreateSession(amqpSessionSettings);
    await session.OpenAsync(....).ConfigureAwait(false);
  }
  catch (Exception exception)
  {
    ....
    session?.Abort();
    throw AmqpExceptionHelper.GetClientException(exception, null,
      session.GetInnerException(), amqpConnection.IsClosing());
  }
  ....
}


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

Проверено проектов
367
Собрано ошибок
13 552

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

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

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

goto PVS-Studio;