text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE252_Unchecked_Return_Value__char_rename_08.c
  Label Definition File: CWE252_Unchecked_Return_Value.string.label.xml
  Template File: point-flaw-08.tmpl.c
  */
  /*
   * @description
   * CWE: 252 Unchecked Return Value
   * Sinks: rename
   *    GoodSink: Check if rename() fails
   *    BadSink : Do not check if rename() fails
   * Flow Variant: 08 Control flow: if(static_returns_t()) and if(static_returns_f())
   *
   * */
  
  #include "std_testcase.h"
  
  #ifdef _WIN32
  # define RENAME rename
  #else
  # define RENAME rename
  #endif
  
  #define OLD_BAD_FILE_NAME "oldbadfilename.txt"
  #define OLD_GOOD_FILE_NAME "oldgoodfilename.txt"
  
  /* The two function below always return the same value, so a tool
     should be able to identify that calls to the functions will always
     return a fixed value. */
  static int static_returns_t()
  {
      return 1;
  }
  
  static int static_returns_f()
  {
      return 0;
  }
  
  #ifndef OMITBAD
  
  void CWE252_Unchecked_Return_Value__char_rename_08_bad()
  {
      if(static_returns_t())
      {
          {
              /* FLAW: Do not check the return value */
              RENAME(OLD_BAD_FILE_NAME, "newbadfilename.txt");
          }
      }
      else
      {
          /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
          {
              /* FIX: check the return value */
              if (RENAME(OLD_GOOD_FILE_NAME, "newgoodfilename.txt") != 0)
              {
                  printLine("rename failed!");
              }
          }
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* good1() uses if(static_returns_f()) instead of if(static_returns_t()) */
  static void good1()
  {
      if(static_returns_f())
      {
          /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
          {
              /* FLAW: Do not check the return value */
              RENAME(OLD_BAD_FILE_NAME, "newbadfilename.txt");
          }
      }
      else
      {
          {
              /* FIX: check the return value */
              if (RENAME(OLD_GOOD_FILE_NAME, "newgoodfilename.txt") != 0)
              {
                  printLine("rename failed!");
              }
          }
      }
  }
  
  /* good2() reverses the bodies in the if statement */
  static void good2()
  {
      if(static_returns_t())
      {
          {
              /* FIX: check the return value */
              if (RENAME(OLD_GOOD_FILE_NAME, "newgoodfilename.txt") != 0)
              {
                  printLine("rename failed!");
              }
          }
      }
      else
      {
          /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
          {
              /* FLAW: Do not check the return value */
              RENAME(OLD_BAD_FILE_NAME, "newbadfilename.txt");
          }
      }
  }
  
  void CWE252_Unchecked_Return_Value__char_rename_08_good()
  {
      good1();
      good2();
  }
  
  #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()...");
      CWE252_Unchecked_Return_Value__char_rename_08_good();
      printLine("Finished good()");
  #endif /* OMITGOOD */
  #ifndef OMITBAD
      printLine("Calling bad()...");
      CWE252_Unchecked_Return_Value__char_rename_08_bad();
      printLine("Finished bad()");
  #endif /* OMITBAD */
      return 0;
  }
  
  #endif
  