text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE190_Integer_Overflow__unsigned_int_fixed_square_66b.c
  Label Definition File: CWE190_Integer_Overflow.label.xml
  Template File: sources-sinks-66b.tmpl.c
  */
  /*
   * @description
   * CWE: 190 Integer Overflow
   * BadSource: fixed Fixed value
   * GoodSource: Small, non-zero
   * Sinks: square
   *    GoodSink: Ensure there is no overflow before performing the squaring operation
   *    BadSink : Square data
   * Flow Variant: 66 Data flow: data passed in an array from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #include <math.h>
  
  #ifndef OMITBAD
  
  void CWE190_Integer_Overflow__unsigned_int_fixed_square_66b_bad_sink(unsigned int data_array[])
  {
      /* copy data out of data_array */
      unsigned int data = data_array[2];
      {
          /* POTENTIAL FLAW: Squaring data could cause an overflow */
          unsigned int result = data * data;
          printUnsignedLine(result);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE190_Integer_Overflow__unsigned_int_fixed_square_66b_goodG2B_sink(unsigned int data_array[])
  {
      unsigned int data = data_array[2];
      {
          /* POTENTIAL FLAW: Squaring data could cause an overflow */
          unsigned int result = data * data;
          printUnsignedLine(result);
      }
  }
  
  /* goodB2G uses the BadSource with the GoodSink */
  void CWE190_Integer_Overflow__unsigned_int_fixed_square_66b_goodB2G_sink(unsigned int data_array[])
  {
      unsigned int data = data_array[2];
      {
          unsigned int result = -1;
          /* FIX: Add a check to prevent an overflow from occurring */
          if (data <= (unsigned int)sqrt((unsigned int)UINT_MAX))
          {
              result = data * data;
              printUnsignedLine(result);
          }
          else
          {
              printLine("Input value is too large to perform arithmetic safely.");
          }
      }
  }
  
  #endif /* OMITGOOD */
  