text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE190_Integer_Overflow__int_max_square_74a.cpp
  Label Definition File: CWE190_Integer_Overflow__int.label.xml
  Template File: sources-sinks-74a.tmpl.cpp
  */
  /*
   * @description
   * CWE: 190 Integer Overflow
   * BadSource: max Set data to the max value for int
   * GoodSource: Set data to a small, non-zero number (two)
   * Sinks: square
   *    GoodSink: Ensure there will not be an overflow before squaring data
   *    BadSink : Square data, which can lead to overflow
   * Flow Variant: 74 Data flow: data passed in a map from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  #include <map>
  
  using namespace std;
  
  namespace CWE190_Integer_Overflow__int_max_square_74
  {
  
  #ifndef OMITBAD
  
  /* bad function declaration */
  void badSink(map<int, int> dataMap);
  
  void bad()
  {
      int data;
      map<int, int> dataMap;
      /* Initialize data */
      data = 0;
      /* POTENTIAL FLAW: Use the maximum value for this type */
      data = INT_MAX;
      /* Put data in a map */
      dataMap[0] = data;
      dataMap[1] = data;
      dataMap[2] = data;
      badSink(dataMap);
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void goodG2BSink(map<int, int> dataMap);
  
  static void goodG2B()
  {
      int data;
      map<int, int> dataMap;
      /* Initialize data */
      data = 0;
      /* FIX: Use a small, non-zero value that will not cause an integer overflow in the sinks */
      data = 2;
      /* Put data in a map */
      dataMap[0] = data;
      dataMap[1] = data;
      dataMap[2] = data;
      goodG2BSink(dataMap);
  }
  
  /* goodB2G uses the BadSource with the GoodSink */
  void goodB2GSink(map<int, int> dataMap);
  
  static void goodB2G()
  {
      int data;
      map<int, int> dataMap;
      /* Initialize data */
      data = 0;
      /* POTENTIAL FLAW: Use the maximum value for this type */
      data = INT_MAX;
      dataMap[0] = data;
      dataMap[1] = data;
      dataMap[2] = data;
      goodB2GSink(dataMap);
  }
  
  void good()
  {
      goodG2B();
      goodB2G();
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  
  /* 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
  
  using namespace CWE190_Integer_Overflow__int_max_square_74; /* so that we can use good and bad easily */
  
  int main(int argc, char * argv[])
  {
      /* seed randomness */
      srand( (unsigned)time(NULL) );
  #ifndef OMITGOOD
      printLine("Calling good()...");
      good();
      printLine("Finished good()");
  #endif /* OMITGOOD */
  #ifndef OMITBAD
      printLine("Calling bad()...");
      bad();
      printLine("Finished bad()");
  #endif /* OMITBAD */
      return 0;
  }
  
  #endif
  