text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE843_Type_Confusion__char_09.c
  Label Definition File: CWE843_Type_Confusion.label.xml
  Template File: sources-sink-09.tmpl.c
  */
  /*
   * @description
   * CWE: 843 Type Confusion
   * BadSource: char Point data to a char data type
   * GoodSource: Point data to an int data type
   * Sink:
   *    BadSink : Attempt to access data as an int
   * Flow Variant: 09 Control flow: if(GLOBAL_CONST_TRUE) and if(GLOBAL_CONST_FALSE)
   *
   * */
  
  #include "std_testcase.h"
  
  #ifndef OMITBAD
  
  void CWE843_Type_Confusion__char_09_bad()
  {
      void * data;
      /* Initialize data */
      data = NULL;
      if(GLOBAL_CONST_TRUE)
      {
          {
              /* FLAW: Point data to a char */
              char charBuffer = 'a';
              data = &charBuffer;
          }
      }
      /* POTENTIAL FLAW: Attempt to access data as an int */
      printIntLine(*((int*)data));
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B1() - use goodsource and badsink by changing the GLOBAL_CONST_TRUE to GLOBAL_CONST_FALSE */
  static void goodG2B1()
  {
      void * data;
      /* Initialize data */
      data = NULL;
      if(GLOBAL_CONST_FALSE)
      {
          /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
          printLine("Benign, fixed string");
      }
      else
      {
          {
              /* FIX: Point data to an int */
              int intBuffer = 8;
              data = &intBuffer;
          }
      }
      /* POTENTIAL FLAW: Attempt to access data as an int */
      printIntLine(*((int*)data));
  }
  
  /* goodG2B2() - use goodsource and badsink by reversing the blocks in the if statement */
  static void goodG2B2()
  {
      void * data;
      /* Initialize data */
      data = NULL;
      if(GLOBAL_CONST_TRUE)
      {
          {
              /* FIX: Point data to an int */
              int intBuffer = 8;
              data = &intBuffer;
          }
      }
      /* POTENTIAL FLAW: Attempt to access data as an int */
      printIntLine(*((int*)data));
  }
  
  void CWE843_Type_Confusion__char_09_good()
  {
      goodG2B1();
      goodG2B2();
  }
  
  #endif /* OMITGOOD */
  
  /* 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
  
  int main(int argc, char * argv[])
  {
      /* seed randomness */
      srand( (unsigned)time(NULL) );
  #ifndef OMITGOOD
      printLine("Calling good()...");
      CWE843_Type_Confusion__char_09_good();
      printLine("Finished good()");
  #endif /* OMITGOOD */
  #ifndef OMITBAD
      printLine("Calling bad()...");
      CWE843_Type_Confusion__char_09_bad();
      printLine("Finished bad()");
  #endif /* OMITBAD */
      return 0;
  }
  
  #endif
  