text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE476_NULL_Pointer_Dereference__class_65a.cpp
  Label Definition File: CWE476_NULL_Pointer_Dereference__class.label.xml
  Template File: sources-sink-65a.tmpl.cpp
  */
  /*
   * @description
   * CWE: 476 NULL Pointer Dereference
   * BadSource:  Set data to NULL
   * GoodSource: Initialize data
   * Sinks:
   *    BadSink : Print data
   * Flow Variant: 65 Data/control flow: data passed as an argument from one function to a function in a different source file called via a function pointer
   *
   * */
  
  #include "std_testcase.h"
  
  namespace CWE476_NULL_Pointer_Dereference__class_65
  {
  
  #ifndef OMITBAD
  
  /* bad function declaration */
  void bad_sink(twointsclass * data);
  
  void bad()
  {
      twointsclass * data;
      /* define a function pointer */
      void (*func_ptr) (twointsclass *) = bad_sink;
      /* Initialize data */
      data = NULL;
      /* FLAW: Set data to NULL - it will be used in the sink */
      data = NULL;
      /* use the function pointer */
      func_ptr(data);
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void goodG2B_sink(twointsclass * data);
  
  static void goodG2B()
  {
      twointsclass * data;
      void (*func_ptr) (twointsclass *) = goodG2B_sink;
      /* Initialize data */
      data = NULL;
      {
          twointsclass * tmp = new twointsclass;
          tmp->a = 0;
          tmp->b = 0;
          /* FIX: Initialize data - it will be used in the sink */
          data = tmp;
      }
      func_ptr(data);
  }
  
  void good()
  {
      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 CWE476_NULL_Pointer_Dereference__class_65; // 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
  