From b35c5f019f9dcbee023c54f25be644d90a5a76ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Schl=C3=BCter?= Date: Sun, 2 Sep 2007 17:04:11 +0200 Subject: dump-parse-tree.c (show_char_const): New function. fortran/ * dump-parse-tree.c (show_char_const): New function. (gfc_show_expr): Use it. * expr.c (find_substring_ref): Rework to not keep characters dangling beyond end of string. testsuite/ * gfortran.dg/substr_6.f90: New test. From-SVN: r128027 --- gcc/fortran/expr.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'gcc/fortran/expr.c') diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 8c44028..ebed1f2 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -1329,6 +1329,7 @@ find_substring_ref (gfc_expr *p, gfc_expr **newp) { int end; int start; + int length; char *chr; if (p->ref->u.ss.start->expr_type != EXPR_CONSTANT @@ -1336,13 +1337,16 @@ find_substring_ref (gfc_expr *p, gfc_expr **newp) return FAILURE; *newp = gfc_copy_expr (p); - chr = p->value.character.string; + gfc_free ((*newp)->value.character.string); + end = (int) mpz_get_ui (p->ref->u.ss.end->value.integer); start = (int) mpz_get_ui (p->ref->u.ss.start->value.integer); + length = end - start + 1; - (*newp)->value.character.length = end - start + 1; - strncpy ((*newp)->value.character.string, &chr[start - 1], - (*newp)->value.character.length); + chr = (*newp)->value.character.string = gfc_getmem (length + 1); + (*newp)->value.character.length = length; + memcpy (chr, &p->value.character.string[start - 1], length); + chr[length] = '\0'; return SUCCESS; } -- cgit v1.1