text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE191_Integer_Underflow__char_fixed_53d.c
  Label Definition File: CWE191_Integer_Underflow.label.xml
  Template File: sources-sinks-53d.tmpl.c
  */
  /*
   * @description
   * CWE: 191 Integer Underflow
   * BadSource: fixed Fixed value
   * GoodSource: Small, non-zero
   * Sinks:
   *    GoodSink: Ensure there is no underflow before performing the subtraction
   *    BadSink : Subtract 1 from data
   * Flow Variant: 53 Data flow: data passed as an argument from one function through two others to a fourth; all four functions are in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifndef OMITBAD
  
  void CWE191_Integer_Underflow__char_fixed_53d_bad_sink(char data)
  {
      {
          /* POTENTIAL FLAW: Subtracting 1 from data could cause an integer underflow */
          char result = data - 1;
          printHexCharLine(result);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE191_Integer_Underflow__char_fixed_53d_goodG2B_sink(char data)
  {
      {
          /* POTENTIAL FLAW: Subtracting 1 from data could cause an integer underflow */
          char result = data - 1;
          printHexCharLine(result);
      }
  }
  
  /* goodB2G uses the BadSource with the GoodSink */
  void CWE191_Integer_Underflow__char_fixed_53d_goodB2G_sink(char data)
  {
      {
          char result = 0;
          /* FIX: Add a check to prevent an underflow from occurring */
          if (data > CHAR_MIN)
          {
              result = data - 1;
              printHexCharLine(result);
          }
          else
          {
              printLine("Input value is too small to perform arithmetic safely.");
          }
      }
  }
  
  #endif /* OMITGOOD */
  