This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Bug fortran/23065] MAXPATHLEN usage in fortran/{scanner,module}.c
- From: Tobias Schlüter <tobias dot schlueter at physik dot uni-muenchen dot de>
- To: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- Cc: pinskia at gcc dot gnu dot org <gcc-bugzilla at gcc dot gnu dot org>,kargl at gcc dot gnu dot org, fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Mon, 15 Aug 2005 00:02:20 +0200
- Subject: Re: [Bug fortran/23065] MAXPATHLEN usage in fortran/{scanner,module}.c
- References: <20050725203426.23065.schwinge-bugzilla-gcc.gnu.org@nic-nac-project.de> <20050801164617.32652.qmail@sourceware.org> <20050801182558.GA7681@troutmask.apl.washington.edu>
Steve Kargl wrote:
> The attached patches uses alloca to remove the use of PATH_MAX
> from gfortran. It also fixes one other nearby hardcoded buffer.
>
> This has been bubblestrapped and regression tested on amd64-*-freebsd.
>
> 2005-08-01 Steven G. Kargl <kargls@comcast.net>
>
> PR fortran/23065
> * gfortran.h: Remove PATH_MAX definition.
> * module.c (write_module,gfc_dump_module): Use alloca to allocate buffers.
> * scanner.s (gfc_release_include_path,form_from_filename): Ditto.
^
typo.
> --- 1131,1142 ----
> const char *fileext;
> int i;
>
> ! /* Find end of file name. Note, filename is either a NULL pointer or
> ! a NUL terminated string. */
> i = 0;
> ! while (filename[i] != '\0')
> i++;
>
> /* Find last period. */
> while (i >= 0 && (filename[i] != '.'))
> i--;
If filename ever were a NULL pointer this would break, but it won't ever be
because gfc_post_options explicitly sets it to the empty string if no filename
is supplied on the command line.
The patch is ok if you remove the if in the beginning of gfc_new_file, i.e. change
try
gfc_new_file (const char *filename, gfc_source_form form)
{
try result;
if (filename != NULL)
{
gfc_source_file = gfc_getmem (strlen (filename) + 1);
strcpy (gfc_source_file, filename);
}
else
gfc_source_file = NULL;
to gcc_assert(filename) plus the if part.
thanks,
- Tobi