From: Harald Anlauf <anlauf@gmx.de>
To: Thomas Koenig <tkoenig@netcologne.de>
Cc: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] PR fortran/70070 - ICE on initializing character data beyond min/max bound
Date: Mon, 25 Jan 2021 21:43:00 +0100 [thread overview]
Message-ID: <trinity-8abf2257-5929-46f1-b6f8-355291d4677d-1611607380795@3c-app-gmx-bap58> (raw)
In-Reply-To: <3fe4244d-60b1-c7f1-10d2-4761428ca64f@netcologne.de>
[-- Attachment #1: Type: text/plain, Size: 580 bytes --]
Hi Thomas,
> Gesendet: Montag, 25. Januar 2021 um 19:58 Uhr
> Von: "Thomas Koenig" <tkoenig@netcologne.de>
> a.f90:3:10:
>
> 3 | print a(0:3)
> | 1
> Error: Substring start index at (1) is less than one
> a.f90:4:10:
>
> 4 | print a(1:4)
> | 1
> Error: Substring end index at (1) exceeds the string length
>
> Could you maybe just re-use these?
this is done in the attached patch. Committed and pushed to master.
> OK with adjusted error message. Thanks for the patch!
Thanks for the review!
Harald
[-- Attachment #2: pr70070.patch-v2 --]
[-- Type: application/octet-stream, Size: 1528 bytes --]
diff --git a/gcc/fortran/data.c b/gcc/fortran/data.c
index 1313b335c86..13e3506dd1e 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
{
diff --git a/gcc/testsuite/gfortran.dg/pr70070.f90 b/gcc/testsuite/gfortran.dg/pr70070.f90
new file mode 100644
index 00000000000..04a6dd585ab
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr70070.f90
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR fortran/70070 - ICE on initializing character data beyond min/max bound
+
+program p
+ character(1) :: a, b
+ data (a(i:i),i=0,0) /1*'#'/ ! { dg-error "Substring start index" }
+ data (b(i:i),i=2,3) /2*'#'/ ! { dg-error "Substring end index" }
+end
prev parent reply other threads:[~2021-01-25 20:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-24 21:12 Harald Anlauf
2021-01-25 18:58 ` Thomas Koenig
2021-01-25 20:43 ` Harald Anlauf [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=trinity-8abf2257-5929-46f1-b6f8-355291d4677d-1611607380795@3c-app-gmx-bap58 \
--to=anlauf@gmx.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=tkoenig@netcologne.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).