Examples of errors detected by the V3001 diagnostic.


V3001. There are identical sub-expressions to the left and to the right of the 'foo' operator.


Umbraco

V3001 There are identical sub-expressions 'FocalPoint.Top != 0.5m' to the left and to the right of the '&&' operator. ImageCropDataSet.cs 58


public class ImageCropFocalPoint
{
  [DataMember(Name = "left")]
  public decimal Left { get; set; }

  [DataMember(Name = "top")]
  public decimal Top { get; set; }
}

public bool HasFocalPoint()
{
  return FocalPoint != null &&
         FocalPoint.Top != 0.5m && FocalPoint.Top != 0.5m;
}

Umbraco

V3001 There are identical sub-expressions 'node != null' to the left and to the right of the '&&' operator. BaseTree.cs 503


protected virtual void OnBeforeNodeRender(ref XmlTree sender,
                                          ref XmlTreeNode node,
                                          EventArgs e)
{
  if (node != null && node != null)
  {
    if (BeforeNodeRender != null)
      BeforeNodeRender(ref sender, ref node, e);
  }
}

Umbraco

V3001 There are identical sub-expressions 'key == ExifTag.WindowsTitle' to the left and to the right of the '||' operator. ExifPropertyCollection.cs 78


public void Set (ExifTag key, string value)
{
  if (items.ContainsKey (key))
    items.Remove (key);
  if (key == ExifTag.WindowsTitle ||         // <=
      key == ExifTag.WindowsTitle ||         // <=
      key == ExifTag.WindowsComment ||
      key == ExifTag.WindowsAuthor ||
      key == ExifTag.WindowsKeywords ||
      key == ExifTag.WindowsSubject) {
    items.Add (key, new WindowsByteString (key, value));
  ....
}

SharpDevelop

V3001 There are identical sub-expressions 'mc_a.Location.File' to the left and to the right of the '!=' operator. membercache.cs 1306


static
MemberCore GetLaterDefinedMember (MemberSpec a, MemberSpec b)
{
  var mc_a = a.MemberDefinition as MemberCore;
  var mc_b = b.MemberDefinition as MemberCore;

  ....

  if (mc_a.Location.File != mc_a.Location.File)
    return mc_b;

  return mc_b.Location.Row > mc_a.Location.Row ? mc_b : mc_a;
}

Microsoft Code Contracts

V3001 There are identical sub-expressions 'semanticType.Name == null' to the left and to the right of the '||' operator. ContractsProvider.cs 694


public bool TryGetTypeReference(....)
{
  ....
  if (semanticType.Name == null || semanticType.Name == null)
    goto ReturnFalse;
  cciType = new Microsoft.Cci.MutableCodeModel.NamespaceTypeR....
  {
    ContainingUnitNamespace = cciNamespace,
    GenericParameterCount = (ushort) (....),
    InternFactory = Host.InternFactory,
    IsValueType = semanticType.IsValueType,
    IsEnum = semanticType.TypeKind == TypeKind.Enum,
    Name = Host.NameTable.GetNameFor(semanticType.Name),
    TypeCode=CSharpToCCIHelper.GetPrimitiveTypeCode(semanticType)
  };
  goto ReturnTrue;'
  ....
}

Similar errors can be found in some other places:

  • V3001 There are identical sub-expressions 'semanticType.Name == null' to the left and to the right of the '||' operator. ContractsProvider.cs 714

MonoDevelop

V3001 There are identical sub-expressions 'string.IsNullOrEmpty (fixtureTypeName)' to the left and to the right of the '||' operator. MonoDevelop.NUnit NUnitProjectTestSuite.cs 84


protected override SourceCodeLocation
  GetSourceCodeLocation (string fixtureTypeNamespace,
                         string fixtureTypeName,
                         string methodName)
{
  if (string.IsNullOrEmpty (fixtureTypeName) ||
      string.IsNullOrEmpty (fixtureTypeName))
    return null;
  ....
}

MonoDevelop

V3001 There are identical sub-expressions 'doc.Editor != null' to the left and to the right of the '&&' operator. MonoDevelop.AspNet RazorCSharpParser.cs 180


bool TryAddDocument (string fileName,
         out OpenRazorDocument currentDocument)
{
  ....
  var guiDoc = IdeApp.Workbench.GetDocument (fileName);
  if (guiDoc != null && guiDoc.Editor != null)
  ....
  guiDoc.Closed += (sender, args) =>
  {
    var doc = sender as MonoDevelop.Ide.Gui.Document;
    if (doc.Editor != null && doc.Editor != null)
    ....
  }
  ....
}

MonoDevelop

V3001 There are identical sub-expressions 'mc_a.Location.File' to the left and to the right of the '!=' operator. ICSharpCode.NRefactory.CSharp membercache.cs 1319


static MemberCore
  GetLaterDefinedMember(MemberSpec a, MemberSpec b)
{
  var mc_a = a.MemberDefinition as MemberCore;
  var mc_b = b.MemberDefinition as MemberCore;
  if (mc_a == null)
    return mc_b;

  if (mc_b == null)
    return mc_a;

  if (a.DeclaringType.MemberDefinition !=
      b.DeclaringType.MemberDefinition)
    return mc_b;

  if (mc_a.Location.File != mc_a.Location.File)
    return mc_b;

  return mc_b.Location.Row > mc_a.Location.Row ? mc_b : mc_a;
}

MonoDevelop

V3001 There are identical sub-expressions 'resultIter != null' to the left and to the right of the '&&' operator. MonoDevelop.Ide GtkTreeModelResult.cs 125


public override AppResult
  Property(string propertyName, object value)
{
  if (resultIter != null && resultIter.HasValue) {
    var objectToCompare =
           TModel.GetValue (resultIter.Value, Column);
    return MatchProperty (propertyName, objectToCompare, value);
  }

  return MatchProperty (propertyName, ParentWidget, value);
}

TreeIter? resultIter;

Similar errors can be found in some other places:

  • V3001 There are identical sub-expressions 'resultIter != null' to the left and to the right of the '&&' operator. MonoDevelop.Ide GtkTreeModelResult.cs 135

MonoDevelop

V3001 There are identical sub-expressions 'member1.DeclaredAccessibility' to the left and to the right of the '!=' operator. CSharpBinding AbstractImplementInterfaceService.CodeAction.cs 544


Accessibility DeclaredAccessibility { get; }
bool IsStatic { get; }

private bool MembersMatch(ISymbol member1, ISymbol member2)
{
  if (member1.Kind != member2.Kind)
  {
    return false;
  }

  if (member1.DeclaredAccessibility !=
      member1.DeclaredAccessibility
   || member1.IsStatic != member1.IsStatic)
  {
    return false;
  }

  if (member1.ExplicitInterfaceImplementations().Any() ||
      member2.ExplicitInterfaceImplementations().Any())
  {
    return false;
  }

  return SignatureComparer
    .HaveSameSignatureAndConstraintsAndReturnTypeAndAccessors(
       member1, member2, this.IsCaseSensitive);
}

MonoDevelop

V3001 There are identical sub-expressions 'member1.IsStatic' to the left and to the right of the '!=' operator. CSharpBinding AbstractImplementInterfaceService.CodeAction.cs 545


Accessibility DeclaredAccessibility { get; }
bool IsStatic { get; }

private bool MembersMatch(ISymbol member1, ISymbol member2)
{
  if (member1.Kind != member2.Kind)
  {
    return false;
  }

  if (member1.DeclaredAccessibility !=
      member1.DeclaredAccessibility
   || member1.IsStatic != member1.IsStatic)
  {
    return false;
  }

  if (member1.ExplicitInterfaceImplementations().Any() ||
      member2.ExplicitInterfaceImplementations().Any())
  {
    return false;
  }

  return SignatureComparer
    .HaveSameSignatureAndConstraintsAndReturnTypeAndAccessors(
       member1, member2, this.IsCaseSensitive);
}

IronPython and IronRuby

V3001 There are identical sub-expressions 'litBegin.Value is int' to the left and to the right of the '&&' operator. IronRubyParseTreeOps.cs 277


private bool Enter(RangeExpression/*!*/ node, bool isCondition) {
  ....
  if (!isCondition && litBegin != null && litEnd != null
    && litBegin.Value is int && litBegin.Value is int) {
    _result = MakeNode(NodeKind.lit, new Range(
      (int)litBegin.Value, (int)litEnd.Value,
      node.IsExclusive));
  } else {
    ....
  }
  ....
}

IronPython and IronRuby

V3001 There are identical sub-expressions 'self is PythonDictionary' to the left and to the right of the '||' operator. IronPython ObjectOps.cs 452


private static PythonTuple ReduceProtocol2(
  CodeContext/*!*/ context, object self) {
  ....
  if (self is PythonDictionary || self is PythonDictionary) {
    dictIterator = PythonOps.Invoke(context, self,
      "iteritems", ArrayUtils.EmptyObjects);
  }
  ....
}

Samples by the Infragistics Company

V3001 There are identical sub-expressions 'double.IsNaN(Latitude)' to the left and to the right of the '||' operator. WeatherStation.cs 25


public bool IsValid
{
  get {
    var valid =
      double.IsNaN(Latitude) || double.IsNaN(Latitude) ||
      this.Weather.DateTime == Weather.DateTimeInitial;
    return valid;
  }
}

Samples by the Infragistics Company

V3001 There are identical sub-expressions 'xmax > rc.Right' to the left and to the right of the '&&' operator. Geometry. Geometry.CubicSpline.cs 529


private static int clipSegment(....)
{
  if (xmax > rc.Right && xmax > rc.Right)
  {
    return -1;
  }
}

Samples by the Infragistics Company

V3001 There are identical sub-expressions 'LineSpacingType == Infrastructure.LineSpacingTypes.Exactly' to the left and to the right of the '||' operator. ParagraphSettingsPreviewAdapter.cs 268


void ParagraphSettingsPreviewAdapter_PropertyChanged(
 object sender, PropertyChangedEventArgs e) {
  ....
  if (LineSpacingType == Infrastructure.LineSpacingTypes.Exactly
   || LineSpacingType == Infrastructure.LineSpacingTypes.Exactly)
  { .... }

Space Engineers

V3001 There are identical sub-expressions 'property.Name == "AxisScale"' to the left and to the right of the '||' operator. Sandbox.Graphics MyParticleEmitter.cs 352


void DeserializeV0(XmlReader reader)
{
  ....
  if (property.Name == "Rotation"  ||
      property.Name == "AxisScale" ||
      property.Name == "AxisScale")
    continue;
  ....
}

Xenko

V3001 There are identical sub-expressions 'SupportFormat(converting.Format)' to the left and to the right of the '&&' operator. SiliconStudio.TextureConverter DxtTexLib.cs 141


public bool CanHandleRequest(TexImage image, IRequest request)
{
  ....
  return SupportFormat(compress.Format) &&
           SupportFormat(image.Format);
  ....
  return SupportFormat(converting.Format) &&
           SupportFormat(converting.Format);      // <=
  ....
}

Xenko

V3001 There are identical sub-expressions 'rescale.Filter == Filter.Rescaling.Bicubic' to the left and to the right of the '||' operator. SiliconStudio.TextureConverter DxtTexLib.cs 148


public enum Rescaling
{
  Box = 0,
  Bicubic = 1,
  Bilinear = 2,
  BSpline = 3,
  CatmullRom = 4,
  Lanczos3 = 5,
  Nearest,
}

public bool CanHandleRequest(TexImage image, IRequest request)
{
  ....
  return rescale.Filter == Filter.Rescaling.Box      ||
           rescale.Filter == Filter.Rescaling.Bicubic ||  // <=
           rescale.Filter == Filter.Rescaling.Bicubic ||  // <=
           rescale.Filter == Filter.Rescaling.Nearest;
  ....
}

Xenko

V3001 There are identical sub-expressions 'box.Maximum.X - box.Minimum.X > sphere.Radius' to the left and to the right of the '&&' operator. SiliconStudio.Core.Mathematics Collision.cs 1322


public static ContainmentType BoxContainsSphere(
                                ref BoundingBox box,
                                ref BoundingSphere sphere)
{
  ....
  if ((((box.Minimum.X + sphere.Radius <= sphere.Center.X)    &&
        (sphere.Center.X <= box.Maximum.X - sphere.Radius))   &&
       ((box.Maximum.X - box.Minimum.X > sphere.Radius)      &&
       (box.Minimum.Y + sphere.Radius <= sphere.Center.Y)))  &&
      (((sphere.Center.Y <= box.Maximum.Y - sphere.Radius)   &&
        (box.Maximum.Y - box.Minimum.Y > sphere.Radius))    &&
      (((box.Minimum.Z + sphere.Radius <= sphere.Center.Z)    &&
      (sphere.Center.Z <= box.Maximum.Z - sphere.Radius))     &&
        (box.Maximum.X - box.Minimum.X > sphere.Radius))))
  ....
}

Xenko

V3001 There are identical sub-expressions 'item.Key == null' to the left and to the right of the '||' operator. SiliconStudio.Core MultiValueSortedDictionary.cs 318


public bool Remove(KeyValuePair<TKey, Tvalue> item)
{
  if (item.Key == null ||
      item.Key == null)
    throw new ArgumentException();
  ....
}

Xamarin.Forms

V3001 There are identical sub-expressions 'RwWait' to the left and to the right of the '|' operator. SplitOrderedList.cs 458


const int RwWait  = 1;
const int RwWrite = 2;
const int RwRead  = 4;
....

public void EnterReadLock()
{
  ....

  if ((Interlocked.Add(ref _rwlock, RwRead) &
      (RwWait | RwWait)) == 0)
    return;

  ....
}

Xamarin.Forms

V3001 There are identical sub-expressions 'Left == 0' to the left and to the right of the '&&' operator. Thickness.cs 29


public double Left   { get; set; }
public double Top    { get; set; }
public double Right  { get; set; }
public double Bottom { get; set; }

internal bool IsDefault
{
  get { return Left  == 0 && Top  == 0 &&
               Right == 0 && Left == 0; }
}

Accord.Net

V3001 There are identical sub-expressions 'image.PixelFormat != PixelFormat.Format32bppRgb' to the left and to the right of the '&&' operator. Accord.Imaging BlobCounterBase.cs 670


public Blob[] GetObjects(UnmanagedImage image,
                         bool extractInOriginalSize)
{
  ....
  if ((image.PixelFormat != PixelFormat.Format24bppRgb)    &&
      (image.PixelFormat != PixelFormat.Format8bppIndexed) &&
      (image.PixelFormat != PixelFormat.Format32bppRgb)    &&
      (image.PixelFormat != PixelFormat.Format32bppArgb)   &&
      (image.PixelFormat != PixelFormat.Format32bppRgb)    &&
      (image.PixelFormat != PixelFormat.Format32bppPArgb)
      )
  ....
}

Similar errors can be found in some other places:

  • V3001 There are identical sub-expressions 'image.PixelFormat != PixelFormat.Format32bppRgb' to the left and to the right of the '&&' operator. Accord.Imaging BlobCounterBase.cs 833

Mono

V3001 There are identical sub-expressions 'u.TypeArguments.Length' to the left and to the right of the '!=' operator. generic.cs 3135


public int ExactInference (TypeSpec u, TypeSpec v)
{
  ....
  var ac_u = (ArrayContainer) u;
  var ac_v = (ArrayContainer) v;
  ....
  var ga_u = u.TypeArguments;
  var ga_v = v.TypeArguments;
  ....
  if (u.TypeArguments.Length != u.TypeArguments.Length) // <=
    return 0;

  ....
}

Mono

V3001 There are identical sub-expressions 'j' to the left and to the right of the '-' operator. ecore.cs 4832


bool BetterFunction (....)
{
  ....
  int j = 0;
  ....
  if (!candidate_params &&
      !candidate_pd.FixedParameters [j - j]  // <=
                   .HasDefaultValue) {
    return true;
  }
  ....
  if (!candidate_pd.FixedParameters [j - 1].HasDefaultValue &&
       best_pd.FixedParameters [j - 1].HasDefaultValue)
    return true;

  if (candidate_pd.FixedParameters [j - 1].HasDefaultValue &&
      best_pd.HasParams)
    return true;
  ....
}

Mono

V3001 There are identical sub-expressions 'c != '<'' to the left and to the right of the '&&' operator. HttpListenerRequest.cs 99


internal void SetRequestLine (string req)
{
  ....
  if ((ic >= 'A' && ic <= 'Z') ||
      (ic > 32 && c < 127 && c != '(' && c != ')' && c != '<' &&
       c != '<' && c != '>'  && c != '@'  && c != ','         &&
       c != ';' && c != ':'  && c != '\\' && c != '"'         &&
       c != '/' && c != '['  && c != ']'  && c != '?'         &&
       c != '=' && c != '{'  && c != '}'))
    continue;
  ....
}

Mono

V3001 There are identical sub-expressions 'grid_style.LinkHoverColor' to the left and to the right of the '!=' operator. DataGrid.cs 2225


protected virtual bool ShouldSerializeLinkHoverColor ()
{
  return grid_style.LinkHoverColor != grid_style.LinkHoverColor;
}

Mono

V3001 There are identical sub-expressions 'value1.ClassName' to the left and to the right of the '==' operator. ThemeVisualStyles.cs 2141


static bool AreEqual (VisualStyleElement value1,
                      VisualStyleElement value2)
{
  return
    value1.ClassName == value1.ClassName && // <=
    value1.Part == value2.Part &&
    value1.State == value2.State;
}

GitExtensions

V3001 There are identical sub-expressions to the left and to the right of the '||' operator. GitUI FormRemotes.cs 192


private void ConfigureRemotes()
{
  ....
  if (!remoteHead.IsRemote ||
    localHead.IsRemote ||
    !string.IsNullOrEmpty(
      localHead.GetTrackingRemote(localConfig)) || // <=
    !string.IsNullOrEmpty(
      localHead.GetTrackingRemote(localConfig)) || // <=
    remoteHead.IsTag ||
    localHead.IsTag ||
    !remoteHead.Name.ToLower().Contains(
      localHead.Name.ToLower()) ||
    !remoteHead.Name.ToLower().Contains(
      _remote.ToLower()))
    continue;
  ....
}

Similar errors can be found in some other places:

  • V3001 There are identical sub-expressions '!curItem.IsSourceEqual(item.NeutralValue)' to the left and to the right of the '&&' operator. TranslationApp TranslationHelpers.cs 112

PowerShell

V3001 There are identical sub-expressions 'BaseMaximumVersion != null' to the left and to the right of the '&&' operator. System.Management.Automation ImportModuleCommand.cs 1663


internal Version BaseMinimumVersion { get; set; }
internal Version BaseMaximumVersion { get; set; }
protected override void ProcessRecord()
{
  if (BaseMaximumVersion != null &&
      BaseMaximumVersion != null &&
      BaseMaximumVersion < BaseMinimumVersion)
  {
    string message = StringUtil.Format(
      Modules.MinimumVersionAndMaximumVersionInvalidRange,
      BaseMinimumVersion,
      BaseMaximumVersion);
    throw new PSArgumentOutOfRangeException(message);
  }
  ....
}

PowerShell

V3001 There are identical sub-expressions to the left and to the right of the '&&' operator. System.Management.Automation serverremotesession.cs 633


internal static class RemoteDataNameStrings
{
  ....
  internal const string MinRunspaces = "MinRunspaces";
  internal const string MaxRunspaces = "MaxRunspaces";
  ....
}
internal void ExecuteConnect(....)
{
  ....
  if
  (
    connectRunspacePoolObject.Data
      .Properties[RemoteDataNameStrings.MinRunspaces] != null
    &&
    connectRunspacePoolObject.Data
      .Properties[RemoteDataNameStrings.MinRunspaces] != null
  )
  {
    try
    {
      clientRequestedMinRunspaces =
        RemotingDecoder.GetMinRunspaces(
          connectRunspacePoolObject.Data);
      clientRequestedMaxRunspaces =
        RemotingDecoder.GetMaxRunspaces(
          connectRunspacePoolObject.Data);
      clientRequestedRunspaceCount = true;
    }
    ....
  }
  ....
}

Media Portal 2

V3001 There are identical sub-expressions 'screenWidth != _screenSize.Width' to the left and to the right of the '||' operator. MainForm.cs 922


protected override void WndProc(ref Message m)
{
  int bitDepth = m.WParam.ToInt32();
  int screenWidth = m.LParam.ToInt32() & 0xFFFF;
  int screenHeight = m.LParam.ToInt32() >> 16;  // <=
  if (bitDepth != _screenBpp ||
      screenWidth != _screenSize.Width ||
      screenWidth != _screenSize.Width)         // <=
  {
    ....
  }

  ....
}

Instead of 'screenWidth' and '_screenSize.Width', we must use 'screenHeight' and '_screenSize.Height'.

Similar errors can be found in some other places:

  • V3001 There are identical sub-expressions 'p == null' to the left and to the right of the '||' operator. TriangulationConstraint.cs 141

PascalABC.NET

V3001 There are identical sub-expressions 'token.Kind == openBracketToken' to the left and to the right of the '||' operator. ICSharpCode.SharpDevelop NRefactoryInsightWindowHandler.cs 66


readonly int eofToken,
             commaToken,
             openParensToken,
             closeParensToken,
             openBracketToken,
             closeBracketToken,
             openBracesToken,
             closeBracesToken,
             statementEndToken;

public void InitializeOpenedInsightWindow(....)
{
  ....
  if (token.Kind == openParensToken ||
      token.Kind == openBracketToken ||
      token.Kind == openBracketToken) {  // <=
    bracketCount++;
  }
  ....
}

Similar errors can be found in some other places:

  • V3001 There are identical sub-expressions 'File.Exists(pdbFileName)' to the left and to the right of the '&&' operator. VisualPascalABCNET RunnerManagerHandlers.cs 165
  • V3001 There are identical sub-expressions '_pascal_set_constant.values != null' to the left and to the right of the '&&' operator. TreeConverter syntax_tree_visitor.cs 4553


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