Examples of errors detected by the V3093 diagnostic

V3093. The operator evaluates both operands. Perhaps a short-circuit operator should be used instead.


Accord.Net

V3093 The '&' operator evaluates both operands. Perhaps a short-circuit '&&' operator should be used instead. Accord.Math JaggedSingularValueDecompositionF.cs 461


public JaggedSingularValueDecompositionF(
         Single[][] value,
         bool computeLeftSingularVectors,
         bool computeRightSingularVectors,
         bool autoTranspose,
         bool inPlace)
{
  ....
  if ((k < nct) & (s[k] != 0.0))
  ....
}

Identical errors can be found in some other places:

  • V3093 The '&' operator evaluates both operands. Perhaps a short-circuit '&&' operator should be used instead. Accord.Math JaggedSingularValueDecompositionF.cs 510
  • V3093 The '&' operator evaluates both operands. Perhaps a short-circuit '&&' operator should be used instead. Accord.Math JaggedSingularValueDecompositionF.cs 595
  • V3093 The '&' operator evaluates both operands. Perhaps a short-circuit '&&' operator should be used instead. Accord.Math JaggedSingularValueDecomposition.cs 461
  • And 3 additional diagnostic messages.

Old NASA World Wind (C#)

V3093 The '&' operator evaluates both operands. Perhaps a short-circuit '&&' operator should be used instead. utils.cs 280

V3093 The '&' operator evaluates both operands. Perhaps a short-circuit '&&' operator should be used instead. utils.cs 291


public static String GetDocumentSource(....)
{
  ....
  int iSize = 2048;
  byte[] bytedata = new byte[2048];
  int iBOMLength = 0;

  while (true)
  {
    iSize = memstream.Read(bytedata, 0, bytedata.Length);
    if (iSize > 0)
    {
      if (!IsUnicodeDetermined)
      {
        ....
        if ((bytedata[0] == 0xEF) &
            (bytedata[1] == 0xBB) &
            (bytedata[2] == 0xBF)) //UTF8
            {
              IsUTF8 = true;
              IsBOMPresent = true;
            }

        if (!IsUTF16LE & !IsUTF16BE & !IsUTF8)
         {
            if ((bytedata[1] == 0) &
                (bytedata[3] == 0) &
                (bytedata[5] == 0) &
                (bytedata[7] == 0))
                {
                  IsUTF16LE = true; //best guess
                }
          }
      ....
    }
  }
  ....
}

NUnit

V3093 The '&' operator evaluates both operands. Perhaps a short-circuit '&&' operator should be used instead. nunit.framework-2.0 SubPathConstraint.cs 55


public class SubPathConstraint : PathConstraint
{
    protected override bool Matches(string actual)
    {
      return actual != null &
        IsSubPath(Canonicalize(expected), Canonicalize(actual));
    }
}

public abstract class PathConstraint : StringConstraint
{
    protected string Canonicalize(string path)
    {
        if (Path.DirectorySeparatorChar !=
            Path.AltDirectorySeparatorChar)
            path = path.Replace(Path.AltDirectorySeparatorChar,
                                Path.DirectorySeparatorChar);
        ....
    }
}


Do you make errors in the code?

Check your code
with PVS-Studio

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

goto PVS-Studio;