/* goodG2B() - use goodsource and badsink */ public static void GoodG2BSink(CWE369_Divide_by_Zero__float_listen_tcp_divide_67a.Container dataContainer) { float data = dataContainer.containerOne; /* POTENTIAL FLAW: Possibly divide 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_listen_tcp_divide_67a.Container dataContainer) { float data = dataContainer.containerOne; /* FIX: Check for value of or near zero before dividing */ if (Math.Abs(data) > 0.000001) { int result = (int)(100.0 / data); IO.WriteLine(result); } else { IO.WriteLine("This would result in a divide by zero"); } }