text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE190_Integer_Overflow__int64_t_max_add_66b.c
  Label Definition File: CWE190_Integer_Overflow.label.xml
  Template File: sources-sinks-66b.tmpl.c
  */
  /*
   * @description
   * CWE: 190 Integer Overflow
   * BadSource: max Set data to the max value for int64_t
   * GoodSource: Set data to a small, non-zero number (two)
   * Sinks: add
   *    GoodSink: Ensure there will not be an overflow before adding 1 to data
   *    BadSink : Add 1 to data, which can cause an overflow
   * Flow Variant: 66 Data flow: data passed in an array from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifndef OMITBAD
  
  void CWE190_Integer_Overflow__int64_t_max_add_66b_badSink(int64_t dataArray[])
  {
      /* copy data out of dataArray */
      int64_t data = dataArray[2];
      {
          /* POTENTIAL FLAW: Adding 1 to data could cause an overflow */
          int64_t result = data + 1;
          printLongLongLine(result);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE190_Integer_Overflow__int64_t_max_add_66b_goodG2BSink(int64_t dataArray[])
  {
      int64_t data = dataArray[2];
      {
          /* POTENTIAL FLAW: Adding 1 to data could cause an overflow */
          int64_t result = data + 1;
          printLongLongLine(result);
      }
  }
  
  /* goodB2G uses the BadSource with the GoodSink */
  void CWE190_Integer_Overflow__int64_t_max_add_66b_goodB2GSink(int64_t dataArray[])
  {
      int64_t data = dataArray[2];
      /* FIX: Add a check to prevent an overflow from occurring */
      if (data < LLONG_MAX)
      {
          int64_t result = data + 1;
          printLongLongLine(result);
      }
      else
      {
          printLine("data value is too large to perform arithmetic safely.");
      }
  }
  
  #endif /* OMITGOOD */
  