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))
....
}
Similar 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
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
}
}
....
}
}
....
}
Similar errors can be found in some other places:
- V3093 The '&' operator evaluates both operands. Perhaps a short-circuit '&&' operator should be used instead. utils.cs 291
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);
....
}
}
Azure PowerShell
V3093 The '|' operator evaluates both operands. Perhaps a short-circuit '||' operator should be used instead. PSKeyVaultCertificatePolicy.cs 114
internal CertificatePolicy ToCertificatePolicy()
{
....
if (!string.IsNullOrWhiteSpace(SubjectName) ||
DnsNames != null ||
Ekus != null ||
KeyUsage != null | // <=
ValidityInMonths.HasValue)
{
....
}
....
}
Chocolatey
V3093 [CWE-480] The '&' operator evaluates both operands. Perhaps a short-circuit '&&' operator should be used instead. Platform.cs 64
public static PlatformType get_platform()
{
switch (Environment.OSVersion.Platform)
{
case PlatformID.MacOSX:
{
....
}
case PlatformID.Unix:
if(file_system.directory_exists("/Applications")
& file_system.directory_exists("/System")
& file_system.directory_exists("/Users")
& file_system.directory_exists("/Volumes"))
{
return PlatformType.Mac;
}
else
return PlatformType.Linux;
default:
return PlatformType.Windows;
}
}
Open XML SDK
V3093 The '&' operator evaluates both operands. Perhaps a short-circuit '&&' operator should be used instead. UniqueAttributeValueConstraint.cs 60
public override ValidationErrorInfo ValidateCore(ValidationContext context)
{
....
foreach (var e in root.Descendants(....))
{
if (e != element & e.GetType() == elementType) // <=
{
var eValue = e.ParsedState.Attributes[_attribute];
if (eValue.HasValue && _comparer.Equals(....))
{
return true;
}
}
}
....
}