private void CheckParameter(ParameterDefinition parameter) { // nothing to do if it could not be resolved if (parameter == null) { return; } // out parameters can't be null if (parameter.IsOut) { return; } int sequence = parameter.Index; // ldarg this - 'this' cannot be null if (sequence == -1) { return; } // was there a null check done before ? if (has_null_check.Get(sequence)) { return; } // make sure we don't report it more than once has_null_check.Set(sequence); // ignore a value type parameter (as long as its not an array of value types) TypeReference ptype = parameter.ParameterType; // take care of references (ref) ByReferenceType rt = (ptype as ByReferenceType); if (rt != null) { ptype = rt.ElementType; } if (ptype.IsValueType && !ptype.IsArray) { return; } // last chance, if the type is a generic type constrained not to be nullable GenericParameter gp = (parameter.ParameterType as GenericParameter); if ((gp != null) && gp.HasNotNullableValueTypeConstraint) { return; } // nullable with no check // we assume a better control of family members so this is less severe Severity s = (parameter.Method as MethodDefinition).IsFamily ? Severity.Medium : Severity.High; Runner.Report(parameter, s, Confidence.Normal); }
private void ReportBadParameters(Collection <ParameterDefinition> parameters) { for (var i = 0; i < parameters.Count; i++) { long bit = 1 << i; if (!methodBitmask.Get(bit)) { continue; } Runner.Report(parameters [i], Severity.Medium, Confidence.Normal); } }
public void BitmaskSeverity () { Bitmask<Severity> x = new Bitmask<Severity> (); Assert.IsFalse (x.Get (Severity.Audit), "Empty/Audit"); Assert.AreEqual (0, x.GetHashCode (), "Empty/GetHashCode"); Assert.AreEqual ("0", x.ToString (), "Empty/ToString"); x.Set (Severity.Audit); Assert.IsTrue (x.Get (Severity.Audit), "Set/Audit"); Assert.AreEqual (16, x.GetHashCode (), "GetHashCode"); Assert.AreEqual ("10000", x.ToString (), "ToString"); Assert.IsTrue (x.Equals (x), "Equals(self)"); Assert.IsTrue (x.Equals ((object) x), "Equals((object)self)"); Assert.IsFalse (x.Equals (Severity.Audit), "Equals"); x.Clear (Severity.Audit); Assert.IsFalse (x.Get (Severity.Audit), "Clear/Audit"); }
public void SetDown() { Bitmask <long> x = new Bitmask <long> (false); for (int i = 0; i < 64; i++) { Assert.IsFalse(x.Get(i), "false#" + i.ToString()); } x.SetDown(48); for (int i = 0; i <= 48; i++) { Assert.IsTrue(x.Get(i), "SetDown#" + i.ToString()); } for (int i = 49; i < 64; i++) { Assert.IsFalse(x.Get(i), "SetDown#" + i.ToString()); } }
public void BitmaskSeverity() { Bitmask <Severity> x = new Bitmask <Severity> (); Assert.IsFalse(x.Get(Severity.Audit), "Empty/Audit"); Assert.AreEqual(0, x.GetHashCode(), "Empty/GetHashCode"); Assert.AreEqual("0", x.ToString(), "Empty/ToString"); x.Set(Severity.Audit); Assert.IsTrue(x.Get(Severity.Audit), "Set/Audit"); Assert.AreEqual(16, x.GetHashCode(), "GetHashCode"); Assert.AreEqual("10000", x.ToString(), "ToString"); Assert.IsTrue(x.Equals(x), "Equals(self)"); Assert.IsTrue(x.Equals((object)x), "Equals((object)self)"); Assert.IsFalse(x.Equals(Severity.Audit), "Equals"); x.Clear(Severity.Audit); Assert.IsFalse(x.Get(Severity.Audit), "Clear/Audit"); }
public void SetUp() { Bitmask <long> x = new Bitmask <long> (true); for (int i = 0; i < 64; i++) { Assert.IsTrue(x.Get(i), "true#" + i.ToString()); } x.ClearAll(); x.SetUp(16); for (int i = 0; i < 16; i++) { Assert.IsFalse(x.Get(i), "SetUp#" + i.ToString()); } for (int i = 16; i < 64; i++) { Assert.IsTrue(x.Get(i), "SetUp#" + i.ToString()); } }
public void SetClearAll() { Bitmask <long> x = new Bitmask <long> (); for (int i = 0; i < 64; i++) { Assert.IsFalse(x.Get(i), "Default#" + i.ToString()); } x.SetAll(); for (int i = 0; i < 64; i++) { Assert.IsTrue(x.Get(i), "SetAll#" + i.ToString()); } x.ClearAll(); for (int i = 0; i < 64; i++) { Assert.IsFalse(x.Get(i), "ClearAll#" + i.ToString()); } }
void CheckDisposeCalls(MethodDefinition method, Instruction ins) { Instruction instance = ins.TraceBack(method); if (instance == null) { return; } VariableDefinition v = instance.GetVariable(method); ulong index = v == null ? UInt64.MaxValue : (ulong)v.Index; if (v != null && locals.Get(index)) { if (!IsInsideFinallyBlock(method, ins)) { string msg = String.Format(CultureInfo.InvariantCulture, "Local {0}is not guaranteed to be disposed of.", GetFriendlyNameOrEmpty(v)); Runner.Report(method, Severity.Medium, Confidence.Normal, msg); } locals.Clear(index); } }
public void SetDown () { Bitmask<long> x = new Bitmask<long> (false); for (int i = 0; i < 64; i++) { Assert.IsFalse (x.Get (i), "false#" + i.ToString ()); } x.SetDown (48); for (int i = 0; i <= 48; i++) { Assert.IsTrue (x.Get (i), "SetDown#" + i.ToString ()); } for (int i = 49; i < 64; i++) { Assert.IsFalse (x.Get (i), "SetDown#" + i.ToString ()); } }
public void SetUp () { Bitmask<long> x = new Bitmask<long> (true); for (int i = 0; i < 64; i++) { Assert.IsTrue (x.Get (i), "true#" + i.ToString ()); } x.ClearAll (); x.SetUp (16); for (int i = 0; i < 16; i++) { Assert.IsFalse (x.Get (i), "SetUp#" + i.ToString ()); } for (int i = 16; i < 64; i++) { Assert.IsTrue (x.Get (i), "SetUp#" + i.ToString ()); } }
public void SetClearAll () { Bitmask<long> x = new Bitmask<long> (); for (int i = 0; i < 64; i++) { Assert.IsFalse (x.Get (i), "Default#" + i.ToString ()); } x.SetAll (); for (int i = 0; i < 64; i++) { Assert.IsTrue (x.Get (i), "SetAll#" + i.ToString ()); } x.ClearAll (); for (int i = 0; i < 64; i++) { Assert.IsFalse (x.Get (i), "ClearAll#" + i.ToString ()); } }