Avoid crashing when an input file could not be opened
authorDodji Seketeli <dodji@redhat.com>
Fri, 24 Jan 2014 15:34:03 +0000 (15:34 +0000)
committerDodji Seketeli <dodji@gcc.gnu.org>
Fri, 24 Jan 2014 15:34:03 +0000 (16:34 +0100)
* input.c (add_file_to_cache_tab): Handle the case where fopen
returns NULL.

Signed-off-by: Dodji Seketeli <dodji@seketeli.org>
From-SVN: r207046

gcc/ChangeLog
gcc/input.c

index cdbedad..7feb332 100644 (file)
@@ -1,3 +1,8 @@
+2014-01-24  Dodji Seketeli  <dodji@redhat.com>
+
+       * input.c (add_file_to_cache_tab): Handle the case where fopen
+       returns NULL.
+
 2014-01-23  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR target/59929
index 290680c..547c177 100644 (file)
@@ -293,11 +293,8 @@ add_file_to_cache_tab (const char *file_path)
 {
 
   FILE *fp = fopen (file_path, "r");
-  if (ferror (fp))
-    {
-      fclose (fp);
-      return NULL;
-    }
+  if (fp == NULL)
+    return NULL;
 
   unsigned highest_use_count = 0;
   fcache *r = evicted_cache_tab_entry (&highest_use_count);