text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE190_Integer_Overflow__unsigned_char_rand_square_65a.c
  Label Definition File: CWE190_Integer_Overflow.label.xml
  Template File: sources-sinks-65a.tmpl.c
  */
  /*
   * @description
   * CWE: 190 Integer Overflow
   * BadSource: rand Set data to result of rand()
   * GoodSource: Small, non-zero
   * Sinks: square
   *    GoodSink: Ensure there is no overflow before performing the squaring operation
   *    BadSink : Square 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"
  
  #include <math.h>
  
  #ifndef OMITBAD
  
  /* bad function declaration */
  void CWE190_Integer_Overflow__unsigned_char_rand_square_65b_bad_sink(unsigned char data);
  
  void CWE190_Integer_Overflow__unsigned_char_rand_square_65_bad()
  {
      unsigned char data;
      /* define a function pointer */
      void (*func_ptr) (unsigned char) = CWE190_Integer_Overflow__unsigned_char_rand_square_65b_bad_sink;
      data = ' ';
      /* POTENTIAL FLAW: Use a random value */
      data = (unsigned char)rand();
      /* use the function pointer */
      func_ptr(data);
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE190_Integer_Overflow__unsigned_char_rand_square_65b_goodG2B_sink(unsigned char data);
  
  static void goodG2B()
  {
      unsigned char data;
      void (*func_ptr) (unsigned char) = CWE190_Integer_Overflow__unsigned_char_rand_square_65b_goodG2B_sink;
      data = ' ';
      /* FIX: Use a small, non-zero value that will not cause an overflow in the sinks */
      data = 5;
      func_ptr(data);
  }
  
  /* goodB2G uses the BadSource with the GoodSink */
  void CWE190_Integer_Overflow__unsigned_char_rand_square_65b_goodB2G_sink(unsigned char data);
  
  static void goodB2G()
  {
      unsigned char data;
      void (*func_ptr) (unsigned char) = CWE190_Integer_Overflow__unsigned_char_rand_square_65b_goodB2G_sink;
      data = ' ';
      /* POTENTIAL FLAW: Use a random value */
      data = (unsigned char)rand();
      func_ptr(data);
  }
  
  void CWE190_Integer_Overflow__unsigned_char_rand_square_65_good()
  {
      goodG2B();
      goodB2G();
  }
  
  #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()...");
      CWE190_Integer_Overflow__unsigned_char_rand_square_65_good();
      printLine("Finished good()");
  #endif /* OMITGOOD */
  #ifndef OMITBAD
      printLine("Calling bad()...");
      CWE190_Integer_Overflow__unsigned_char_rand_square_65_bad();
      printLine("Finished bad()");
  #endif /* OMITBAD */
      return 0;
  }
  
  #endif
  