text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE124_Buffer_Underwrite__new_wchar_t_ncpy_52c.cpp
  Label Definition File: CWE124_Buffer_Underwrite__new.label.xml
  Template File: sources-sink-52c.tmpl.cpp
  */
  /*
   * @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: ncpy
   *    BadSink : Copy string to data using wcsncpy
   * 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"
  
  #include <wchar.h>
  
  namespace CWE124_Buffer_Underwrite__new_wchar_t_ncpy_52
  {
  
  /* all the sinks are the same, we just want to know where the hit originated if a tool flags one */
  
  #ifndef OMITBAD
  
  void badSink_c(wchar_t * data)
  {
      {
          wchar_t source[100];
          wmemset(source, L'C', 100-1); /* fill with 'C's */
          source[100-1] = L'\0'; /* null terminate */
          /* POTENTIAL FLAW: Possibly copying data to memory before the destination buffer */
          wcsncpy(data, source, 100-1);
          /* Ensure the destination buffer is null terminated */
          data[100-1] = L'\0';
          printWLine(data);
          /* INCIDENTAL CWE-401: Memory Leak - data may not point to location
           * returned by new [] so can't safely call delete [] on it */
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void goodG2BSink_c(wchar_t * data)
  {
      {
          wchar_t source[100];
          wmemset(source, L'C', 100-1); /* fill with 'C's */
          source[100-1] = L'\0'; /* null terminate */
          /* POTENTIAL FLAW: Possibly copying data to memory before the destination buffer */
          wcsncpy(data, source, 100-1);
          /* Ensure the destination buffer is null terminated */
          data[100-1] = L'\0';
          printWLine(data);
          /* INCIDENTAL CWE-401: Memory Leak - data may not point to location
           * returned by new [] so can't safely call delete [] on it */
      }
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  