text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE190_Integer_Overflow__short_max_postinc_52c.c
  Label Definition File: CWE190_Integer_Overflow.label.xml
  Template File: sources-sinks-52c.tmpl.c
  */
  /*
   * @description
   * CWE: 190 Integer Overflow
   * BadSource: max Set data to the max value for short
   * GoodSource: Set data to a small, non-zero number (two)
   * Sinks: increment
   *    GoodSink: Ensure there will not be an overflow before incrementing data
   *    BadSink : Increment data, which can cause an overflow
   * Flow Variant: 52 Data flow: data passed as an argument from one function to another to another in three different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifndef OMITBAD
  
  void CWE190_Integer_Overflow__short_max_postinc_52c_badSink(short data)
  {
      {
          /* POTENTIAL FLAW: Incrementing data could cause an overflow */
          data++;
          short result = data;
          printIntLine(result);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE190_Integer_Overflow__short_max_postinc_52c_goodG2BSink(short data)
  {
      {
          /* POTENTIAL FLAW: Incrementing data could cause an overflow */
          data++;
          short result = data;
          printIntLine(result);
      }
  }
  
  /* goodB2G uses the BadSource with the GoodSink */
  void CWE190_Integer_Overflow__short_max_postinc_52c_goodB2GSink(short data)
  {
      /* FIX: Add a check to prevent an overflow from occurring */
      if (data < SHRT_MAX)
      {
          data++;
          short result = data;
          printIntLine(result);
      }
      else
      {
          printLine("data value is too large to perform arithmetic safely.");
      }
  }
  
  #endif /* OMITGOOD */
  