[gfortran] Fix PR 13792: Memory corruption

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Thu Jul 15 19:31:00 GMT 2004


PR 13792 was a segfault late in the compiler, its reason was a simple mistake,
 where the lower bound of an array had been freed, even though it shouldn't
have been. The reason of this was that gfc_simplify_bound didn't copy the
expression it returned. In the expression
  i = lbound(a,1)
the expression for the right hand side will get replaced by the result of the
simplification function, and this result will then immediately be freed. This
leads to errors such as the one in PR 13792 if the result has other uses.

Fixed by the below patch, built and tested. I will also change the torture
testcase execute/bounds.f90 to include a test where the simplification
function comes into play.

- Tobi

2004-07-15  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>

	PR fortran/13792
	* simplify.c (gfc_simplify_bound): Copy the bound expression.

Index: simplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/simplify.c,v
retrieving revision 1.4
diff -u -p -r1.4 simplify.c
--- simplify.c  29 May 2004 11:33:30 -0000      1.4
+++ simplify.c  15 Jul 2004 19:22:23 -0000
@@ -1892,9 +1892,9 @@ gfc_simplify_bound (gfc_expr * array, gf

   i = mpz_get_si (dim->value.integer);
   if (upper)
-    return as->upper[i-1];
+    return gfc_copy_expr (as->upper[i-1]);
   else
-    return as->lower[i-1];
+    return gfc_copy_expr (as->lower[i-1]);
 }



More information about the Fortran mailing list