text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE457_Use_of_Uninitialized_Variable__twointsclass_array_declare_no_init_17.cpp
  Label Definition File: CWE457_Use_of_Uninitialized_Variable__twointsclass_array.label.xml
  Template File: sources-sinks-17.tmpl.cpp
  */
  /*
   * @description
   * CWE: 457 Use of Uninitialized Variable
   * BadSource: no_init Don't initialize data
   * GoodSource: Initialize data
   * Sinks: use
   *    GoodSink: Initialize then use data
   *    BadSink : Use data
   * Flow Variant: 17 Control flow: for loops
   * */
  
  #include "std_testcase.h"
  
  namespace CWE457_Use_of_Uninitialized_Variable__twointsclass_array_declare_no_init_17
  {
  
  #ifndef OMITBAD
  
  void bad()
  {
      int i,j;
      TwoIntsClass * data;
      TwoIntsClass dataUninitArray[10];
      data = dataUninitArray;
      for(i = 0; i < 1; i++)
      {
          /* POTENTIAL FLAW: Don't initialize data */
          ; /* empty statement needed for some flow variants */
      }
      for(j = 0; j < 1; j++)
      {
          /* POTENTIAL FLAW: Use data without initializing it */
          for(int i=0; i<10; i++)
          {
              printIntLine(data[i].intOne);
              printIntLine(data[i].intTwo);
          }
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodB2G() - use badsource and goodsink in the for statements */
  static void goodB2G()
  {
      int i,k;
      TwoIntsClass * data;
      TwoIntsClass dataUninitArray[10];
      data = dataUninitArray;
      for(i = 0; i < 1; i++)
      {
          /* POTENTIAL FLAW: Don't initialize data */
          ; /* empty statement needed for some flow variants */
      }
      for(k = 0; k < 1; k++)
      {
          /* FIX: Ensure data is initialized before use */
          for(int i=0; i<10; i++)
          {
              data[i].intOne = i;
              data[i].intTwo = i;
          }
          for(int i=0; i<10; i++)
          {
              printIntLine(data[i].intOne);
              printIntLine(data[i].intTwo);
          }
      }
  }
  
  /* goodG2B() - use goodsource and badsink in the for statements */
  static void goodG2B()
  {
      int h,j;
      TwoIntsClass * data;
      TwoIntsClass dataUninitArray[10];
      data = dataUninitArray;
      for(h = 0; h < 1; h++)
      {
          /* FIX: Completely initialize data */
          for(int i=0; i<10; i++)
          {
              data[i].intOne = i;
              data[i].intTwo = i;
          }
      }
      for(j = 0; j < 1; j++)
      {
          /* POTENTIAL FLAW: Use data without initializing it */
          for(int i=0; i<10; i++)
          {
              printIntLine(data[i].intOne);
              printIntLine(data[i].intTwo);
          }
      }
  }
  
  void good()
  {
      goodB2G();
      goodG2B();
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  
  /* Below is the main(). It is only used when building this testcase on
     its own for testing or for building a binary to use in testing binary
     analysis tools. It is not used when compiling all the testcases as one
     application, which is how source code analysis tools are tested. */
  
  #ifdef INCLUDEMAIN
  
  using namespace CWE457_Use_of_Uninitialized_Variable__twointsclass_array_declare_no_init_17; /* so that we can use good and bad easily */
  
  int main(int argc, char * argv[])
  {
      /* seed randomness */
      srand( (unsigned)time(NULL) );
  #ifndef OMITGOOD
      printLine("Calling good()...");
      good();
      printLine("Finished good()");
  #endif /* OMITGOOD */
  #ifndef OMITBAD
      printLine("Calling bad()...");
      bad();
      printLine("Finished bad()");
  #endif /* OMITBAD */
      return 0;
  }
  
  #endif
  