text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE690_NULL_Deref_From_Return__int64_t_malloc_33.cpp
  Label Definition File: CWE690_NULL_Deref_From_Return.free.label.xml
  Template File: source-sinks-33.tmpl.cpp
  */
  /*
   * @description
   * CWE: 690 Unchecked Return Value To NULL Pointer
   * BadSource: malloc Allocate data using malloc()
   * Sinks:
   *    GoodSink: Check to see if the data allocation failed and if not, use data
   *    BadSink : Don't check for NULL and use data
   * Flow Variant: 33 Data flow: use of a C++ reference to data within the same function
   *
   * */
  
  #include "std_testcase.h"
  
  #include <wchar.h>
  
  namespace CWE690_NULL_Deref_From_Return__int64_t_malloc_33
  {
  
  #ifndef OMITBAD
  
  void bad()
  {
      int64_t * data;
      int64_t * &dataRef = data;
      data = NULL; /* Initialize data */
      /* POTENTIAL FLAW: Allocate memory without checking if the memory allocation function failed */
      data = (int64_t *)malloc(1*sizeof(int64_t));
      {
          int64_t * data = dataRef;
          /* FLAW: Initialize memory buffer without checking to see if the memory allocation function failed */
          data[0] = 5LL;
          printLongLongLine(data[0]);
          free(data);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodB2G() uses the BadSource with the GoodSink */
  static void goodB2G()
  {
      int64_t * data;
      int64_t * &dataRef = data;
      data = NULL; /* Initialize data */
      /* POTENTIAL FLAW: Allocate memory without checking if the memory allocation function failed */
      data = (int64_t *)malloc(1*sizeof(int64_t));
      {
          int64_t * data = dataRef;
          /* FIX: Check to see if the memory allocation function was successful before initializing the memory buffer */
          if (data != NULL)
          {
              data[0] = 5LL;
              printLongLongLine(data[0]);
              free(data);
          }
      }
  }
  
  void good()
  {
      goodB2G();
  }
  
  #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 CWE690_NULL_Deref_From_Return__int64_t_malloc_33; /* 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
  