text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE252_Unchecked_Return_Value__char_fscanf_10.c
  Label Definition File: CWE252_Unchecked_Return_Value.label.xml
  Template File: point-flaw-10.tmpl.c
  */
  /*
   * @description
   * CWE: 252 Unchecked Return Value
   * Sinks: fscanf
   *    GoodSink: Check if fscanf() fails
   *    BadSink : Do not check if fscanf() fails
   * Flow Variant: 10 Control flow: if(globalTrue) and if(globalFalse)
   *
   * */
  
  #include "std_testcase.h"
  
  #ifndef _WIN32
  #include <wchar.h>
  #endif
  
  #ifndef OMITBAD
  
  void CWE252_Unchecked_Return_Value__char_fscanf_10_bad()
  {
      if(globalTrue)
      {
          {
              /* By initializing dataBuffer, we ensure this will not be the
               * CWE 690 (Unchecked Return Value To NULL Pointer) flaw for fgets() and other variants */
              char dataBuffer[100] = "";
              char * data = dataBuffer;
              /* FLAW: Do not check the return value */
              fscanf(stdin, "%99s\0", data);
          }
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* good1() uses if(globalFalse) instead of if(globalTrue) */
  static void good1()
  {
      if(globalFalse)
      {
          /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
          printLine("Benign, fixed string");
      }
      else
      {
          {
              /* By initializing dataBuffer, we ensure this will not be the
               * CWE 690 (Unchecked Return Value To NULL Pointer) flaw for fgets() and other variants */
              char dataBuffer[100] = "";
              char * data = dataBuffer;
              /* FIX: check the return value */
              if (fscanf(stdin, "%99s\0", data) == EOF)
              {
                  printLine("fscanf failed!");
              }
          }
      }
  }
  
  /* good2() reverses the bodies in the if statement */
  static void good2()
  {
      if(globalTrue)
      {
          {
              /* By initializing dataBuffer, we ensure this will not be the
               * CWE 690 (Unchecked Return Value To NULL Pointer) flaw for fgets() and other variants */
              char dataBuffer[100] = "";
              char * data = dataBuffer;
              /* FIX: check the return value */
              if (fscanf(stdin, "%99s\0", data) == EOF)
              {
                  printLine("fscanf failed!");
              }
          }
      }
  }
  
  void CWE252_Unchecked_Return_Value__char_fscanf_10_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_fscanf_10_good();
      printLine("Finished good()");
  #endif /* OMITGOOD */
  #ifndef OMITBAD
      printLine("Calling bad()...");
      CWE252_Unchecked_Return_Value__char_fscanf_10_bad();
      printLine("Finished bad()");
  #endif /* OMITBAD */
      return 0;
  }
  
  #endif
  