text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE190_Integer_Overflow__int64_t_max_multiply_54e.c
  Label Definition File: CWE190_Integer_Overflow.label.xml
  Template File: sources-sinks-54e.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: multiply
   *    GoodSink: Ensure there will not be an overflow before multiplying data by 2
   *    BadSink : If data is positive, multiply by 2, which can cause an overflow
   * Flow Variant: 54 Data flow: data passed as an argument from one function through three others to a fifth; all five functions are in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifndef OMITBAD
  
  void CWE190_Integer_Overflow__int64_t_max_multiply_54e_badSink(int64_t data)
  {
      if(data > 0) /* ensure we won't have an underflow */
      {
          /* POTENTIAL FLAW: if (data*2) > LLONG_MAX, this will overflow */
          int64_t result = data * 2;
          printLongLongLine(result);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE190_Integer_Overflow__int64_t_max_multiply_54e_goodG2BSink(int64_t data)
  {
      if(data > 0) /* ensure we won't have an underflow */
      {
          /* POTENTIAL FLAW: if (data*2) > LLONG_MAX, this will overflow */
          int64_t result = data * 2;
          printLongLongLine(result);
      }
  }
  
  /* goodB2G uses the BadSource with the GoodSink */
  void CWE190_Integer_Overflow__int64_t_max_multiply_54e_goodB2GSink(int64_t data)
  {
      if(data > 0) /* ensure we won't have an underflow */
      {
          /* FIX: Add a check to prevent an overflow from occurring */
          if (data < (LLONG_MAX/2))
          {
              int64_t result = data * 2;
              printLongLongLine(result);
          }
          else
          {
              printLine("data value is too large to perform arithmetic safely.");
          }
      }
  }
  
  #endif /* OMITGOOD */
  