/* goodG2B() - use goodsource and badsink */ public static void GoodG2BSink(CWE369_Divide_by_Zero__float_NetClient_modulo_67a.Container dataContainer) { float data = dataContainer.containerOne; /* POTENTIAL FLAW: Possibly modulo by zero */ int result = (int)(100.0 % data); IO.WriteLine(result); }
/* goodB2G() - use badsource and goodsink */ public static void GoodB2GSink(CWE369_Divide_by_Zero__float_NetClient_modulo_67a.Container dataContainer) { float data = dataContainer.containerOne; /* FIX: Check for value of or near zero before modulo */ if (Math.Abs(data) > 0.000001) { int result = (int)(100.0 % data); IO.WriteLine(result); } else { IO.WriteLine("This would result in a modulo by zero"); } }