Jakub Jelinek <ja...@redhat.com> writes: > On Wed, Jan 22, 2014 at 09:16:02AM +0100, Dodji Seketeli wrote: >> +static fcache* >> +add_file_to_cache_tab (const char *file_path) >> +{ >> + >> + FILE *fp = fopen (file_path, "r"); >> + if (ferror (fp)) >> + { >> + fclose (fp); >> + return NULL; >> + } > > I've seen various segfaults here when playing with preprocessed sources > from PRs (obviously don't have the original source files). > When fopen fails, it just returns NULL, so I don't see why you just don't > do > if (fp == NULL) > return fp;
Right, I am testing the patch below. * input.c (add_file_to_cache_tab): Handle the case where fopen returns NULL. diff --git a/gcc/input.c b/gcc/input.c index 290680c..547c177 100644 --- a/gcc/input.c +++ b/gcc/input.c @@ -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); -- Dodji