PR fortran/99205 - Out of memory with undefined character length
A character variable appearing as a data statement object cannot be automatic, thus it shall have constant length. gcc/fortran/ChangeLog: PR fortran/99205 * data.c (gfc_assign_data_value): Reject non-constant character length for lvalue. * trans-array.c (gfc_conv_array_initializer): Restrict loop to elements which are defined to avoid NULL pointer dereference. gcc/testsuite/ChangeLog: PR fortran/99205 * gfortran.dg/data_char_4.f90: New test. * gfortran.dg/data_char_5.f90: New test.
This commit is contained in:
parent
d38bbb8511
commit
8c21bc6646
4 changed files with 30 additions and 1 deletions
|
@ -595,6 +595,9 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rvalue, mpz_t index,
|
|||
/* An initializer has to be constant. */
|
||||
if (lvalue->ts.u.cl->length == NULL && !(ref && ref->u.ss.length != NULL))
|
||||
return false;
|
||||
if (lvalue->ts.u.cl->length
|
||||
&& lvalue->ts.u.cl->length->expr_type != EXPR_CONSTANT)
|
||||
return false;
|
||||
expr = create_character_initializer (init, last_ts, ref, rvalue);
|
||||
if (!expr)
|
||||
return false;
|
||||
|
|
|
@ -6162,7 +6162,7 @@ gfc_conv_array_initializer (tree type, gfc_expr * expr)
|
|||
case EXPR_ARRAY:
|
||||
/* Create a vector of all the elements. */
|
||||
for (c = gfc_constructor_first (expr->value.constructor);
|
||||
c; c = gfc_constructor_next (c))
|
||||
c && c->expr; c = gfc_constructor_next (c))
|
||||
{
|
||||
if (c->iterator)
|
||||
{
|
||||
|
|
11
gcc/testsuite/gfortran.dg/data_char_4.f90
Normal file
11
gcc/testsuite/gfortran.dg/data_char_4.f90
Normal file
|
@ -0,0 +1,11 @@
|
|||
! { dg-do compile }
|
||||
! PR fortran/99205 - Out of memory with undefined character length
|
||||
! { dg-options "-w" }
|
||||
|
||||
program p
|
||||
character(l) :: c(2) ! { dg-error "must have constant character length" }
|
||||
data c /'a', 'b'/
|
||||
common c
|
||||
end
|
||||
|
||||
! { dg-error "cannot appear in the expression at" " " { target *-*-* } 6 }
|
15
gcc/testsuite/gfortran.dg/data_char_5.f90
Normal file
15
gcc/testsuite/gfortran.dg/data_char_5.f90
Normal file
|
@ -0,0 +1,15 @@
|
|||
! { dg-do compile }
|
||||
! PR fortran/99205 - Issues with non-constant character length
|
||||
|
||||
subroutine sub ()
|
||||
integer :: ll = 4
|
||||
block
|
||||
character(ll) :: c(2) ! { dg-error "non-constant" }
|
||||
data c /'a', 'b'/
|
||||
end block
|
||||
contains
|
||||
subroutine sub1 ()
|
||||
character(ll) :: d(2) ! { dg-error "non-constant" }
|
||||
data d /'a', 'b'/
|
||||
end subroutine sub1
|
||||
end subroutine sub
|
Loading…
Add table
Reference in a new issue