text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE191_Integer_Underflow__int64_t_min_sub_65a.c
  Label Definition File: CWE191_Integer_Underflow.label.xml
  Template File: sources-sinks-65a.tmpl.c
  */
  /*
   * @description
   * CWE: 191 Integer Underflow
   * BadSource: min Set data to the min value for int64_t
   * GoodSource: Set data to a small, non-zero number (negative two)
   * Sinks: sub
   *    GoodSink: Ensure there will not be an underflow before subtracting 1 from data
   *    BadSink : Subtract 1 from data, which can cause an Underflow
   * 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"
  
  #ifndef OMITBAD
  
  /* bad function declaration */
  void CWE191_Integer_Underflow__int64_t_min_sub_65b_badSink(int64_t data);
  
  void CWE191_Integer_Underflow__int64_t_min_sub_65_bad()
  {
      int64_t data;
      /* define a function pointer */
      void (*funcPtr) (int64_t) = CWE191_Integer_Underflow__int64_t_min_sub_65b_badSink;
      data = 0LL;
      /* POTENTIAL FLAW: Use the minimum size of the data type */
      data = LLONG_MIN;
      /* use the function pointer */
      funcPtr(data);
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE191_Integer_Underflow__int64_t_min_sub_65b_goodG2BSink(int64_t data);
  
  static void goodG2B()
  {
      int64_t data;
      void (*funcPtr) (int64_t) = CWE191_Integer_Underflow__int64_t_min_sub_65b_goodG2BSink;
      data = 0LL;
      /* FIX: Use a small, non-zero value that will not cause an underflow in the sinks */
      data = -2;
      funcPtr(data);
  }
  
  /* goodB2G uses the BadSource with the GoodSink */
  void CWE191_Integer_Underflow__int64_t_min_sub_65b_goodB2GSink(int64_t data);
  
  static void goodB2G()
  {
      int64_t data;
      void (*funcPtr) (int64_t) = CWE191_Integer_Underflow__int64_t_min_sub_65b_goodB2GSink;
      data = 0LL;
      /* POTENTIAL FLAW: Use the minimum size of the data type */
      data = LLONG_MIN;
      funcPtr(data);
  }
  
  void CWE191_Integer_Underflow__int64_t_min_sub_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()...");
      CWE191_Integer_Underflow__int64_t_min_sub_65_good();
      printLine("Finished good()");
  #endif /* OMITGOOD */
  #ifndef OMITBAD
      printLine("Calling bad()...");
      CWE191_Integer_Underflow__int64_t_min_sub_65_bad();
      printLine("Finished bad()");
  #endif /* OMITBAD */
      return 0;
  }
  
  #endif
  