Patchwork [fortran] Fix ice-on-valid PR 48876

login
register
mail settings
Submitter Thomas Koenig
Date July 30, 2011, 11:49 a.m.
Message ID <4E33EFD6.3040209@netcologne.de>
Download mbox | patch
Permalink /patch/107501/
State New
Headers show

Comments

Thomas Koenig - July 30, 2011, 11:49 a.m.
Hello world,

the attached, rather self-explanatory patch fixes PR 48876.

OK for trunk?

	Thomas

2011-07-30  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/48876
         * expr.c (gfc_simplify_expr):  If end of a string is less
         than zero, set it to zero.

2011-07-30  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/48876
         * gfortran.dg/string_5.f90:  New test.
! { dg-do compile }
! PR fortran/48876 - this used to segfault.
! Test case contributed by mhp77 (a) gmx.at.
program test
  character ::  string =  "string"( : -1 )
end program test
Steve Kargl - July 30, 2011, 2:22 p.m.
On Sat, Jul 30, 2011 at 01:49:42PM +0200, Thomas Koenig wrote:
> Hello world,
> 
> the attached, rather self-explanatory patch fixes PR 48876.
> 
> OK for trunk?
> 

Yes.  If the problem exists on 4.6, can you apply the patch
to 4.6 as well.
Thomas Koenig - July 30, 2011, 11:11 p.m.
Hello Steve,

> On Sat, Jul 30, 2011 at 01:49:42PM +0200, Thomas Koenig wrote:
>> Hello world,
>>
>> the attached, rather self-explanatory patch fixes PR 48876.
>>
>> OK for trunk?
>>
>
> Yes.  If the problem exists on 4.6, can you apply the patch
> to 4.6 as well.

Applied to trunk and 4.6 (this was not a regression).  Thanks for the 
review!

	Thomas

Patch

Index: expr.c
===================================================================
--- expr.c	(Revision 176933)
+++ expr.c	(Arbeitskopie)
@@ -1839,6 +1839,9 @@  gfc_simplify_expr (gfc_expr *p, int type)
 	  if (p->ref && p->ref->u.ss.end)
 	    gfc_extract_int (p->ref->u.ss.end, &end);
 
+	  if (end < 0)
+	    end = 0;
+
 	  s = gfc_get_wide_string (end - start + 2);
 	  memcpy (s, p->value.character.string + start,
 		  (end - start) * sizeof (gfc_char_t));