text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE127_Buffer_Underread__malloc_wchar_t_memmove_64a.c
  Label Definition File: CWE127_Buffer_Underread__malloc.label.xml
  Template File: sources-sink-64a.tmpl.c
  */
  /*
   * @description
   * CWE: 127 Buffer Under-read
   * BadSource:  Set data pointer to before the allocated memory buffer
   * GoodSource: Set data pointer to the allocated memory buffer
   * Sinks: memmove
   *    BadSink : Copy data to string using memmove
   * Flow Variant: 64 Data flow: void pointer to data passed from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #include <wchar.h>
  
  #ifndef OMITBAD
  
  /* bad function declaration */
  void CWE127_Buffer_Underread__malloc_wchar_t_memmove_64b_bad_sink(void * void_data_ptr);
  
  void CWE127_Buffer_Underread__malloc_wchar_t_memmove_64_bad()
  {
      wchar_t * data;
      data = NULL;
      {
          wchar_t * data_buf = (wchar_t *)malloc(100*sizeof(wchar_t));
          wmemset(data_buf, L'A', 100-1);
          data_buf[100-1] = L'\0';
          /* FLAW: Set data pointer to before the allocated memory buffer */
          data = data_buf - 8;
      }
      CWE127_Buffer_Underread__malloc_wchar_t_memmove_64b_bad_sink(&data);
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE127_Buffer_Underread__malloc_wchar_t_memmove_64b_goodG2B_sink(void * void_data_ptr);
  
  static void goodG2B()
  {
      wchar_t * data;
      data = NULL;
      {
          wchar_t * data_buf = (wchar_t *)malloc(100*sizeof(wchar_t));
          wmemset(data_buf, L'A', 100-1);
          data_buf[100-1] = L'\0';
          /* FIX: Set data pointer to the allocated memory buffer */
          data = data_buf;
      }
      CWE127_Buffer_Underread__malloc_wchar_t_memmove_64b_goodG2B_sink(&data);
  }
  
  void CWE127_Buffer_Underread__malloc_wchar_t_memmove_64_good()
  {
      goodG2B();
  }
  
  #endif /* OMITGOOD */
  
  /* 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
  
  int main(int argc, char * argv[])
  {
      /* seed randomness */
      srand( (unsigned)time(NULL) );
  #ifndef OMITGOOD
      printLine("Calling good()...");
      CWE127_Buffer_Underread__malloc_wchar_t_memmove_64_good();
      printLine("Finished good()");
  #endif /* OMITGOOD */
  #ifndef OMITBAD
      printLine("Calling bad()...");
      CWE127_Buffer_Underread__malloc_wchar_t_memmove_64_bad();
      printLine("Finished bad()");
  #endif /* OMITBAD */
      return 0;
  }
  
  #endif
  