text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE190_Integer_Overflow__int_connect_socket_add_73b.cpp
  Label Definition File: CWE190_Integer_Overflow__int.label.xml
  Template File: sources-sinks-73b.tmpl.cpp
  */
  /*
   * @description
   * CWE: 190 Integer Overflow
   * BadSource: connect_socket Read data using a connect socket (client side)
   * 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: 73 Data flow: data passed in a list from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  #include <list>
  
  using namespace std;
  
  namespace CWE190_Integer_Overflow__int_connect_socket_add_73
  {
  
  #ifndef OMITBAD
  
  void badSink(list<int> dataList)
  {
      /* copy data out of dataList */
      int data = dataList.back();
      {
          /* POTENTIAL FLAW: Adding 1 to data could cause an overflow */
          int result = data + 1;
          printIntLine(result);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void goodG2BSink(list<int> dataList)
  {
      int data = dataList.back();
      {
          /* POTENTIAL FLAW: Adding 1 to data could cause an overflow */
          int result = data + 1;
          printIntLine(result);
      }
  }
  
  /* goodB2G uses the BadSource with the GoodSink */
  void goodB2GSink(list<int> dataList)
  {
      int data = dataList.back();
      /* FIX: Add a check to prevent an overflow from occurring */
      if (data < INT_MAX)
      {
          int result = data + 1;
          printIntLine(result);
      }
      else
      {
          printLine("data value is too large to perform arithmetic safely.");
      }
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  