text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE126_Buffer_Overread__new_wchar_t_memmove_53a.cpp
  Label Definition File: CWE126_Buffer_Overread__new.label.xml
  Template File: sources-sink-53a.tmpl.cpp
  */
  /*
   * @description
   * CWE: 126 Buffer Over-read
   * BadSource:  Use a small buffer
   * GoodSource: Use a large buffer
   * Sink: memmove
   *    BadSink : Copy data to string using memmove
   * 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"
  
  #include <wchar.h>
  
  namespace CWE126_Buffer_Overread__new_wchar_t_memmove_53
  {
  
  #ifndef OMITBAD
  
  /* bad function declaration */
  void badSink_b(wchar_t * data);
  
  void bad()
  {
      wchar_t * data;
      data = NULL;
      /* FLAW: Use a small buffer */
      data = new wchar_t[50];
      wmemset(data, L'A', 50-1); /* fill with 'A's */
      data[50-1] = L'\0'; /* null terminate */
      badSink_b(data);
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* good function declarations */
  void goodG2BSink_b(wchar_t * data);
  
  /* goodG2B uses the GoodSource with the BadSink */
  static void goodG2B()
  {
      wchar_t * data;
      data = NULL;
      /* FIX: Use a large buffer */
      data = new wchar_t[100];
      wmemset(data, L'A', 100-1); /* fill with 'A's */
      data[100-1] = L'\0'; /* null terminate */
      goodG2BSink_b(data);
  }
  
  void good()
  {
      goodG2B();
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  
  /* Below is the main(). It is only used when building this testcase on
     its own for testing or for building a binary to use in testing binary
     analysis tools. It is not used when compiling all the testcases as one
     application, which is how source code analysis tools are tested. */
  
  #ifdef INCLUDEMAIN
  
  using namespace CWE126_Buffer_Overread__new_wchar_t_memmove_53; /* so that we can use good and bad easily */
  
  int main(int argc, char * argv[])
  {
      /* seed randomness */
      srand( (unsigned)time(NULL) );
  #ifndef OMITGOOD
      printLine("Calling good()...");
      good();
      printLine("Finished good()");
  #endif /* OMITGOOD */
  #ifndef OMITBAD
      printLine("Calling bad()...");
      bad();
      printLine("Finished bad()");
  #endif /* OMITBAD */
      return 0;
  }
  
  #endif
  