To get a trial key
fill out the form below
Team License (standard version)
Enterprise License (extended version)
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
GBP
RUB
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
Examples of errors detected by the V306…

Examples of errors detected by the V3063 diagnostic

April 5, 2021

V3063. A part of conditional expression is always true/false if it is evaluated.


Xamarin.Forms

V3063 A part of conditional expression is always true: exception == null. Xamarin.Forms.Xaml ApplyPropertiesVisitor.cs 280


static BindableProperty
GetBindableProperty(Type elementType,
                               string localName,
                               IXmlLineInfo lineInfo,
                               bool throwOnError = false)
{
  ....
  Exception exception = null;
  if (exception == null && bindableFieldInfo == null)
  {
    exception = new XamlParseException(
      string.Format("BindableProperty {0} not found on {1}",
      localName + "Property", elementType.Name), lineInfo);
  }
  ....
}

Accord.Net

V3063 A part of conditional expression is always false: i < low. Accord.Math JaggedEigenvalueDecompositionF.cs 571


private void hqr2()
{
  ....
  int low = 0;
  ....
  for (int i = 0; i < nn; i++)
  {
    if (i < low | i > high)
      ....
  }
  ....
}

Similar errors can be found in some other places:

  • V3063 A part of conditional expression is always false: i < low. Accord.Math JaggedEigenvalueDecompositionF.cs 972
  • V3063 A part of conditional expression is always false: i < low. Accord.Math JaggedEigenvalueDecomposition.cs 571
  • V3063 A part of conditional expression is always false: i < low. Accord.Math JaggedEigenvalueDecomposition.cs 972
  • And 1 additional diagnostic messages.

Old NASA World Wind (C#)

V3063 A part of conditional expression is always false: currentSurfaceImage == null. SurfaceTile.cs 1069


private bool checkSurfaceImageChange()
{
  ....
  SurfaceImage currentSurfaceImage =
  m_ParentWorldSurfaceRenderer.SurfaceImages[i] as SurfaceImage;

  if(currentSurfaceImage.LastUpdate > m_LastUpdate ||
     currentSurfaceImage.Opacity !=
     currentSurfaceImage.ParentRenderable.Opacity)
  {
    if(currentSurfaceImage == null               || // <=
       currentSurfaceImage.ImageTexture == null  ||
       currentSurfaceImage.ImageTexture.Disposed ||
      !currentSurfaceImage.Enabled || ....)
       {
         continue;
       }
       else
       {
         return true;
       }
  }
  ....
}

Similar errors can be found in some other places:

  • V3063 A part of conditional expression is always true: iWildIndex==-1. GPSTrackerPlugin.APRS.cs 87
  • V3063 A part of conditional expression is always true: iWildIndex==-1. GPSTrackerPlugin.NMEA.cs 169
  • V3063 A part of conditional expression is always false: newvalue == null. SchemaTypes.cs 860

Unity3D

V3063 A part of conditional expression is always false: connId < 0. UnityEngine.Networking ConnectionArray.cs 59


public NetworkConnection Get(int connId)
{
  if (connId < 0)
  {
    return m_LocalConnections[Mathf.Abs(connId) - 1];
  }

  if (connId < 0 || connId > m_Connections.Count) // <=
  {
    ....
    return null;
  }

  return m_Connections[connId];
}

Similar errors can be found in some other places:

  • V3063 A part of conditional expression is always true: currentTest != null. UnityTestTools TestRunner.cs 237
  • V3063 A part of conditional expression is always false: connId < 0. UnityEngine.Networking ConnectionArray.cs 86
  • V3063 A part of conditional expression is always true: m_IsServer. UnityEngine.Networking NetworkIdentity.cs 53

GitExtensions

V3063 A part of conditional expression is always true if it is evaluated: button.Enabled. GitUI FormStash.cs 301


private void toolStripButton(...)
{
  var button = (ToolStripButton)sender;
  if (!button.Enabled)
  {
    StashMessage.ReadOnly = true;
  }
  else if (button.Enabled && button.Checked) // <=
  {
    StashMessage.ReadOnly = false;
  }
}

Similar errors can be found in some other places:

  • V3063 A part of conditional expression is always false if it is evaluated: string.IsNullOrEmpty(_mergetool). GitUI FormResolveConflicts.cs 482

Unity C# reference source code

V3063 CWE-571 A part of conditional expression is always true if it is evaluated: pageSize <= 1000. UNETInterface.cs 584


public override bool IsValid()
{
  ....
  return base.IsValid()
    && (pageSize >= 1 || pageSize <= 1000)
    && totalFilters <= 10;
}

AWS SDK for .NET

V3063 [CWE-571] A part of conditional expression is always true if it is evaluated: string.IsNullOrEmpty(inferredIndexName). AWSSDK.DynamoDBv2.PCL ContextInternal.cs 802


private static string GetQueryIndexName(....)
{
  ....
  string inferredIndexName = null;
  if (string.IsNullOrEmpty(specifiedIndexName) &&
      indexNames.Count == 1)
  {
    inferredIndexName = indexNames[0];
  }
  else if (indexNames.Contains(specifiedIndexName,
                               StringComparer.Ordinal))
  {
    inferredIndexName = specifiedIndexName;
  }
  else if (string.IsNullOrEmpty(inferredIndexName) &&  // <=
           indexNames.Count > 0)
    throw new InvalidOperationException("Local Secondary Index range
      key conditions are used but no index could be inferred from
      model. Specified index name = " + specifiedIndexName);
  ....
}

.NET Core Libraries (CoreFX)

V3063 A part of conditional expression is always true if it is evaluated: _rangelist.Count > 0. RegexCharClass.cs 523


public void AddRange(char first, char last)
{
  _rangelist.Add(new SingleRange(first, last)); // <=
  if (....
      && _rangelist.Count > 0  // <=
      && ....)
    ....
}

OpenCvSharp

V3063 A part of conditional expression is always false if it is evaluated: data == null. Mat.cs 3539


private void CheckArgumentsForConvert(....)
{
  ....
  if (data == null)
    throw new ArgumentNullException(nameof(data));

  MatType t = Type();
  if (data == null || (data.Length * dataDimension)      // <=
      (data.Length * dataDimension) % t.Channels != 0)
   ....
}

RunUO

V3063 A part of conditional expression is always true if it is evaluated: m_Serial <= 0x7FFFFFFF. Serial.cs 83


public bool IsItem
{
  get
  {
    return ( m_Serial >= 0x40000000 && m_Serial <= 0x7FFFFFFF );
  }
}

RavenDB

V3063 A part of conditional expression is always true if it is evaluated: Attributes != null. LicenseStatus.cs(28) Raven.Server


public LicenseType Type
{
  get
  {
    if (ErrorMessage != null)
      return LicenseType.Invalid;

    if (Attributes == null)
      return LicenseType.None;

    if (Attributes != null &&                             // <=
        Attributes.TryGetValue("type", out object type) &&
        type is int
    )
    {
      var typeAsInt = (int)type;
      if (Enum.IsDefined(typeof(LicenseType), typeAsInt))
        return (LicenseType)typeAsInt;
    }

    return LicenseType.Community;
  }
}

RavenDB

V3063 A part of conditional expression is always true if it is evaluated: isMethod. QueryParser.cs(1797) Raven.Server


private bool Operator(OperatorField fieldOption, out QueryExpression op)
{
  ....
  switch (match)
  {
    ....
    case "(":
      var isMethod = Method(field, out var method); // <=
      op = method;

      if (
        isMethod &&
        Operator(OperatorField.Optional, out var methodOperator)
      )
      {
        ....
      }

      return isMethod;
    ....
  }
}

private bool Method(FieldExpression field, out MethodExpression op)
{
  var args = ReadMethodArguments();

  op = new MethodExpression(field.FieldValue, args);
  return true;
}

RavenDB

V3063 A part of conditional expression is always false if it is evaluated: m_curEdgeBlock != null. DotNetHeapDumpGraphReader.cs(803) Raven.Debug


private Address GetNextEdge()
{
  if (m_curEdgeBlock == null || m_curEdgeBlock.Count <= m_curEdgeIdx)
  {
    m_curEdgeBlock = null;
    if (m_edgeBlocks.Count == 0)
    {
      throw new ApplicationException(
        "Error not enough edge data.  Giving up on heap dump."
      );
    }

    var nextEdgeBlock = m_edgeBlocks.Dequeue();
    if (
      m_curEdgeBlock != null &&                       // <=
      nextEdgeBlock.Index != m_curEdgeBlock.Index + 1
    )
    {
      throw new ApplicationException(
        "Error expected Node Index " + (m_curEdgeBlock.Index + 1) +
        " Got " + nextEdgeBlock.Index + " Giving up on heap dump."
      );
    }

    m_curEdgeBlock = nextEdgeBlock;
    m_curEdgeIdx = 0;
  }
  return m_curEdgeBlock.Values(m_curEdgeIdx++).Target;
}

OpenRA

V3063 A part of conditional expression is always true if it is evaluated: cancelButton != null. ConfirmationDialogs.cs 78


public static void ButtonPrompt(....)
{
  ....
  var cancelButton = prompt.GetOrNull<ButtonWidget>(
    "CANCEL_BUTTON"
  );
  ....

  if (onCancel != null && cancelButton != null)
  {
    cancelButton.Visible = true;
    cancelButton.Bounds.Y += headerHeight;
    cancelButton.OnClick = () =>
    {
      Ui.CloseWindow();
      if (onCancel != null)
        onCancel();
    };

    if (!string.IsNullOrEmpty(cancelText) && cancelButton != null)
      cancelButton.GetText = () => cancelText;
  }
  ....
}

OpenRA

V3063 A part of conditional expression is always true if it is evaluated: terrainGeometryTrait != null. MapEditorLogic.cs 35


public class MapEditorLogic : ChromeLogic
{
  public MapEditorLogic(....)
  {
    var editorViewport = widget
                         .Get<EditorViewportControllerWidget>("MAP_EDITOR");

    var gridButton = widget.GetOrNull<ButtonWidget>("GRID_BUTTON");
    var terrainGeometryTrait = world.WorldActor
                                  .Trait<TerrainGeometryOverlay>();

    if (gridButton != null && terrainGeometryTrait != null) // <=
    {
      ....
    }

    var copypasteButton = widget.GetOrNull<ButtonWidget>("COPYPASTE_BUTTON");
    if (copypasteButton != null)
    {
      ....
    }

    var copyFilterDropdown = widget.Get<DropDownButtonWidget>(....);
    copyFilterDropdown.OnMouseDown = _ =>
    {
      copyFilterDropdown.RemovePanel();
      copyFilterDropdown.AttachPanel(CreateCategoriesPanel());
    };

    var coordinateLabel = widget.GetOrNull<LabelWidget>("COORDINATE_LABEL");
    if (coordinateLabel != null)
    {
      ....
    }

    ....
  }
  ....
}

public sealed class Actor : ....
{
  ....
  public T Trait<T>()
  {
    return World.TraitDict.Get<T>(this);
  }
  ....
}

class TraitDictionary
{
  ....
  public T Get<T>(Actor actor)
  {
    CheckDestroyed(actor);
    return InnerGet<T>().Get(actor); // InnerGet<T> returns TraitContainer<T>
  }
  ....
}

class TraitContainer<T> : ITraitContainer
{
  ....
  public T Get(Actor actor)
  {
    var result = GetOrDefault(actor);
    if (result == null)
      throw new InvalidOperationException(....);
    return result;
  }
  ....
}

EFCore

V3063 A part of conditional expression is always true if it is evaluated: targetType != null. EFCore InternalEntityTypeBuilder.cs 3370


public virtual InternalEntityTypeBuilder? GetTargetEntityTypeBuilder(....)
{
  ....
  var memberType = navigation.MemberInfo?.GetMemberType();

  if (memberType != null)
  {
    targetType = memberType.TryGetSequenceType() ?? memberType;

    if (   targetType != null                                           // <=
        && targetEntityType.Name == Metadata.Model
                                            .GetDisplayName(targetType))
    {
      targetEntityType = new TypeIdentity(targetType, Metadata.Model);
    }
  }
  ....
}

Popular related articles
Static analysis as part of the development process in Unreal Engine

Date: 06.27.2017

Author: Andrey Karpov

Unreal Engine continues to develop as new code is added and previously written code is changed. What is the inevitable consequence of ongoing development in a project? The emergence of new bugs in th…
The Ultimate Question of Programming, Refactoring, and Everything

Date: 04.14.2016

Author: Andrey Karpov

Yes, you've guessed correctly - the answer is "42". In this article you will find 42 recommendations about coding in C++ that can help a programmer avoid a lot of errors, save time and effort. The au…
PVS-Studio ROI

Date: 01.30.2019

Author: Andrey Karpov

Occasionally, we're asked a question, what monetary value the company will receive from using PVS-Studio. We decided to draw up a response in the form of an article and provide tables, which will sho…
The Evil within the Comparison Functions

Date: 05.19.2017

Author: Andrey Karpov

Perhaps, readers remember my article titled "Last line effect". It describes a pattern I've once noticed: in most cases programmers make an error in the last line of similar text blocks. Now I want t…
Technologies used in the PVS-Studio code analyzer for finding bugs and potential vulnerabilities

Date: 11.21.2018

Author: Andrey Karpov

A brief description of technologies used in the PVS-Studio tool, which let us effectively detect a large number of error patterns and potential vulnerabilities. The article describes the implementati…
Free PVS-Studio for those who develops open source projects

Date: 12.22.2018

Author: Andrey Karpov

On the New 2019 year's eve, a PVS-Studio team decided to make a nice gift for all contributors of open-source projects hosted on GitHub, GitLab or Bitbucket. They are given free usage of PVS-Studio s…
PVS-Studio for Java

Date: 01.17.2019

Author: Andrey Karpov

In the seventh version of the PVS-Studio static analyzer, we added support of the Java language. It's time for a brief story of how we've started making support of the Java language, how far we've co…
Characteristics of PVS-Studio Analyzer by the Example of EFL Core Libraries, 10-15% of False Positives

Date: 07.31.2017

Author: Andrey Karpov

After I wrote quite a big article about the analysis of the Tizen OS code, I received a large number of questions concerning the percentage of false positives and the density of errors (how many erro…
The Last Line Effect

Date: 05.31.2014

Author: Andrey Karpov

I have studied many errors caused by the use of the Copy-Paste method, and can assure you that programmers most often tend to make mistakes in the last fragment of a homogeneous code block. I have ne…
The way static analyzers fight against false positives, and why they do it

Date: 03.20.2017

Author: Andrey Karpov

In my previous article I wrote that I don't like the approach of evaluating the efficiency of static analyzers with the help of synthetic tests. In that article, I give the example of a code fragment…

Comments (0)

Next comments

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →
Accept