text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE194_Unexpected_Sign_Extension__rand_malloc_63a.c
  Label Definition File: CWE194_Unexpected_Sign_Extension.label.xml
  Template File: sources-sink-63a.tmpl.c
  */
  /*
   * @description
   * CWE: 194 Unexpected Sign Extension
   * BadSource: rand Set data to result of rand(), which could be negative
   * GoodSource: Positive integer
   * Sinks: malloc
   *    BadSink : Allocate memory using malloc() with the size of data
   * Flow Variant: 63 Data flow: pointer to data passed from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifndef OMITBAD
  
  /* bad function declaration */
  void CWE194_Unexpected_Sign_Extension__rand_malloc_63b_bad_sink(short * data_ptr);
  
  void CWE194_Unexpected_Sign_Extension__rand_malloc_63_bad()
  {
      short data;
      /* Initialize data */
      data = 0;
      /* POTENTIAL FLAW: Use a random value that could be less than 0 */
      data = (short)RAND32();
      CWE194_Unexpected_Sign_Extension__rand_malloc_63b_bad_sink(&data);
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE194_Unexpected_Sign_Extension__rand_malloc_63b_goodG2B_sink(short * data);
  
  static void goodG2B()
  {
      short data;
      /* Initialize data */
      data = 0;
      /* FIX: Use a positive integer less than &InitialDataSize&*/
      data = 100-1;
      CWE194_Unexpected_Sign_Extension__rand_malloc_63b_goodG2B_sink(&data);
  }
  
  void CWE194_Unexpected_Sign_Extension__rand_malloc_63_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()...");
      CWE194_Unexpected_Sign_Extension__rand_malloc_63_good();
      printLine("Finished good()");
  #endif /* OMITGOOD */
  #ifndef OMITBAD
      printLine("Calling bad()...");
      CWE194_Unexpected_Sign_Extension__rand_malloc_63_bad();
      printLine("Finished bad()");
  #endif /* OMITBAD */
      return 0;
  }
  
  #endif
  