diff options
author | Harald Anlauf <anlauf@gmx.de> | 2021-01-25 21:33:53 +0100 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2021-01-25 21:33:53 +0100 |
commit | a61efd469371b71483d42afa1038e6a8c16baf4a (patch) | |
tree | 325f4339f5cf76eca1a456594853196752e1b628 /gcc/fortran/data.c | |
parent | d6f1cf644c45b76a27b6a6869dedaa030e3c7570 (diff) | |
download | gcc-a61efd469371b71483d42afa1038e6a8c16baf4a.zip gcc-a61efd469371b71483d42afa1038e6a8c16baf4a.tar.gz gcc-a61efd469371b71483d42afa1038e6a8c16baf4a.tar.bz2 |
PR fortran/70070 - ICE on initializing character data beyond min/max bound
Check for initialization of substrings beyond bounds in DATA statements.
gcc/fortran/ChangeLog:
PR fortran/70070
* data.c (create_character_initializer): Check substring indices
against bounds.
(gfc_assign_data_value): Catch error returned from
create_character_initializer.
gcc/testsuite/ChangeLog:
PR fortran/70070
* gfortran.dg/pr70070.f90: New test.
Diffstat (limited to 'gcc/fortran/data.c')
-rw-r--r-- | gcc/fortran/data.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/gcc/fortran/data.c b/gcc/fortran/data.c index 1313b33..13e3506 100644 --- a/gcc/fortran/data.c +++ b/gcc/fortran/data.c @@ -183,6 +183,19 @@ create_character_initializer (gfc_expr *init, gfc_typespec *ts, } } + if (start < 0) + { + gfc_error ("Substring start index at %L is less than one", + &ref->u.ss.start->where); + return NULL; + } + if (end > init->value.character.length) + { + gfc_error ("Substring end index at %L exceeds the string length", + &ref->u.ss.end->where); + return NULL; + } + if (rvalue->ts.type == BT_HOLLERITH) { for (size_t i = 0; i < (size_t) len; i++) @@ -576,6 +589,8 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rvalue, mpz_t index, if (lvalue->ts.u.cl->length == NULL && !(ref && ref->u.ss.length != NULL)) return false; expr = create_character_initializer (init, last_ts, ref, rvalue); + if (!expr) + return false; } else { |