text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE194_Unexpected_Sign_Extension__rand_malloc_54e.c
  Label Definition File: CWE194_Unexpected_Sign_Extension.label.xml
  Template File: sources-sink-54e.tmpl.c
  */
  /*
   * @description
   * CWE: 194 Unexpected Sign Extension
   * BadSource: rand Set data to result of rand(), which could be negative
   * GoodSource: Positive integer
   * Sink: malloc
   *    BadSink : Allocate memory using malloc() with the size of data
   * Flow Variant: 54 Data flow: data passed as an argument from one function through three others to a fifth; all five functions are in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  /* all the sinks are the same, we just want to know where the hit originated if a tool flags one */
  
  #ifndef OMITBAD
  
  void CWE194_Unexpected_Sign_Extension__rand_malloc_54e_bad_sink(short data)
  {
      {
          /* Assume we want to allocate a relatively small buffer */
          if (data < 100)
          {
              /* POTENTIAL FLAW: malloc() takes a size_t (unsigned int) as input and therefore if it is negative,
               * the coversion will cause malloc() to allocate a very large amount of data or fail */
              char * data_buf = (char *)malloc(data);
              /* Do something with data_buf */
              memset(data_buf, 'A', data-1);
              data_buf[data-1] = '\0';
              printLine(data_buf);
              free(data_buf);
          }
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE194_Unexpected_Sign_Extension__rand_malloc_54e_goodG2B_sink(short data)
  {
      {
          /* Assume we want to allocate a relatively small buffer */
          if (data < 100)
          {
              /* POTENTIAL FLAW: malloc() takes a size_t (unsigned int) as input and therefore if it is negative,
               * the coversion will cause malloc() to allocate a very large amount of data or fail */
              char * data_buf = (char *)malloc(data);
              /* Do something with data_buf */
              memset(data_buf, 'A', data-1);
              data_buf[data-1] = '\0';
              printLine(data_buf);
              free(data_buf);
          }
      }
  }
  
  #endif /* OMITGOOD */
  