On 24/12/15 16:38, Jim MacArthur wrote:
Botstrapped and tested for regressions on x86_64-pc-linux-gnu. There is
a test case for the bug included.
I missed out the test case when creating the first patch. This one
should have it.
PR fortran/69043
* scanner.c (load_file): Abort and show an error if stat() shows the
path is a directory.
Index: gcc/fortran/scanner.c
===================================================================
--- gcc/fortran/scanner.c (revision 231945)
+++ gcc/fortran/scanner.c (working copy)
@@ -2200,6 +2200,8 @@ load_file (const char *realfilename, const char *d
FILE *input;
int len, line_len;
bool first_line;
+ struct stat st;
+ int stat_result;
const char *filename;
/* If realfilename and displayedname are different and non-null then
surely realfilename is the preprocessed form of
@@ -2242,6 +2244,16 @@ load_file (const char *realfilename, const char *d
current_file->filename, current_file->line, filename);
return false;
}
+
+ stat_result = stat (realfilename, &st);
+ if (stat_result == 0 && st.st_mode & S_IFDIR)
+ {
+ fprintf (stderr, "%s:%d: Error: Included path '%s'"
+ " is a directory.\n",
+ current_file->filename, current_file->line, filename);
+ fclose (input);
+ return false;
+ }
}
/* Load the file.
Index: gcc/testsuite/gfortran.dg/include_9.f
===================================================================
--- gcc/testsuite/gfortran.dg/include_9.f (revision 0)
+++ gcc/testsuite/gfortran.dg/include_9.f (working copy)
@@ -0,0 +1,7 @@
+! { dg-do compile }
+
+ include '/'
+ program main
+ end program
+
+! { dg-error "is a directory" " " { target *-*-* } 3 }