text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE124_Buffer_Underwrite__malloc_wchar_t_cpy_54e.c
  Label Definition File: CWE124_Buffer_Underwrite__malloc.label.xml
  Template File: sources-sink-54e.tmpl.c
  */
  /*
   * @description
   * CWE: 124 Buffer Underwrite
   * BadSource:  Set data pointer to before the allocated memory buffer
   * GoodSource: Set data pointer to the allocated memory buffer
   * Sink: cpy
   *    BadSink : Copy string to data using wcscpy
   * Flow Variant: 54 Data flow: data passed as an argument from one function through three others to a fifth; all five functions are in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #include <wchar.h>
  
  /* all the sinks are the same, we just want to know where the hit originated if a tool flags one */
  
  #ifndef OMITBAD
  
  void CWE124_Buffer_Underwrite__malloc_wchar_t_cpy_54e_bad_sink(wchar_t * data)
  {
      {
          wchar_t src[100];
          wmemset(src, L'C', 100-1); /* fill with 'C's */
          src[100-1] = L'\0'; /* null terminate */
          /* POTENTIAL FLAW: Possibly copying data to memory before the destination buffer */
          wcscpy(data, src);
          printWLine(data);
          /* INCIDENTAL CWE-401: Memory Leak - data may not point to location
             returned by malloc() so can't safely call free() on it */
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE124_Buffer_Underwrite__malloc_wchar_t_cpy_54e_goodG2B_sink(wchar_t * data)
  {
      {
          wchar_t src[100];
          wmemset(src, L'C', 100-1); /* fill with 'C's */
          src[100-1] = L'\0'; /* null terminate */
          /* POTENTIAL FLAW: Possibly copying data to memory before the destination buffer */
          wcscpy(data, src);
          printWLine(data);
          /* INCIDENTAL CWE-401: Memory Leak - data may not point to location
             returned by malloc() so can't safely call free() on it */
      }
  }
  
  #endif /* OMITGOOD */
  