This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, fortran] PR24398 - broken module files


This patch deals with a problem in which something other than a gfortran module file was given to read_module; the resulting error was more than a little incomprehensible. The fix is to verify that the first two words of the first line read "GFORTRAN module", using module.c's parser. I do not see any point in a testcase for this.

Regtested on FC5/Athlon - Steve Kargl has OK'd this on the PR, so I will submit tonight.

Paul

2006-10-10 Paul Thomas <pault@gcc.gnu.org>

   PR fortran/24398
   * module.c (gfc_use_module): Check that the first words in a
   module file are 'GFORTRAN module'.


Index: gcc/fortran/module.c
===================================================================
*** gcc/fortran/module.c	(revision 117436)
--- gcc/fortran/module.c	(working copy)
*************** gfc_use_module (void)
*** 3798,3812 ****
    iomode = IO_INPUT;
    module_line = 1;
    module_column = 1;
  
!   /* Skip the first two lines of the module.  */
!   /* FIXME: Could also check for valid two lines here, instead.  */
    line = 0;
    while (line < 2)
      {
        c = module_char ();
        if (c == EOF)
  	bad_module ("Unexpected end of module");
        if (c == '\n')
  	line++;
      }
--- 3805,3827 ----
    iomode = IO_INPUT;
    module_line = 1;
    module_column = 1;
+   start = 0;
  
!   /* Skip the first two lines of the module, after checking that this is
!      a gfortran module file.  */
    line = 0;
    while (line < 2)
      {
        c = module_char ();
        if (c == EOF)
  	bad_module ("Unexpected end of module");
+       if (start++ < 2)
+ 	parse_name (c);
+       if ((start == 1 && strcmp (atom_name, "GFORTRAN") != 0)
+ 	    || (start == 2 && strcmp (atom_name, " module") != 0))
+ 	gfc_fatal_error ("File '%s' opened at %C is not a GFORTRAN module "
+ 			  "file", filename);
+ 
        if (c == '\n')
  	line++;
      }
2006-10-10  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/24398
	* module.c (gfc_use_module): Check that the first words in a
	module file are 'GFORTRAN module'.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]