text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE197_Numeric_Truncation_Error__int_connect_socket_to_char_66b.c
  Label Definition File: CWE197_Numeric_Truncation_Error__int.label.xml
  Template File: sources-sink-66b.tmpl.c
  */
  /*
   * @description
   * CWE: 197 Numeric Truncation Error
   * BadSource: connect_socket Read data using a connect socket (client side)
   * GoodSource: Less than CHAR_MAX
   * Sinks: to_char
   *    BadSink : Convert data to a char
   * Flow Variant: 66 Data flow: data passed in an array from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifdef _WIN32
  # include <winsock2.h>
  # include <windows.h>
  # include <direct.h>
  # pragma comment(lib, "ws2_32") /* include ws2_32.lib when linking */
  # define CLOSE_SOCKET closesocket
  #else /* NOT _WIN32 */
  # define INVALID_SOCKET -1
  # define SOCKET_ERROR -1
  # define CLOSE_SOCKET close
  # define SOCKET int
  #endif
  
  #define TCP_PORT 27015
  #define CHAR_ARRAY_SIZE sizeof(data)*sizeof(data)
  
  #ifndef OMITBAD
  
  void CWE197_Numeric_Truncation_Error__int_connect_socket_to_char_66b_bad_sink(int data_array[])
  {
      /* copy data out of data_array */
      int data = data_array[2];
      {
          /* POTENTIAL FLAW: Convert data to a char, possibly causing a truncation error */
          char c = (char)data;
          printHexCharLine(c);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE197_Numeric_Truncation_Error__int_connect_socket_to_char_66b_goodG2B_sink(int data_array[])
  {
      int data = data_array[2];
      {
          /* POTENTIAL FLAW: Convert data to a char, possibly causing a truncation error */
          char c = (char)data;
          printHexCharLine(c);
      }
  }
  
  #endif /* OMITGOOD */
  